tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
lexicographical_compare.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
5#define TETL_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
6
7#include <etl/_functional/less.hpp>
8
9namespace etl {
10
11/// \brief Checks if the first range `[f1, l1)` is lexicographically
12/// less than the second range `[f2, l2)`.
13///
14/// https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare
15///
16/// \ingroup algorithm
17template <typename InputIt1, typename InputIt2, typename Compare>
18[[nodiscard]] constexpr auto lexicographical_compare(InputIt1 f1, InputIt1 l1, InputIt2 f2, InputIt2 l2, Compare comp)
19 -> bool
20{
21 for (; (f1 != l1) and (f2 != l2); ++f1, (void)++f2) {
22 if (comp(*f1, *f2)) {
23 return true;
24 }
25 if (comp(*f2, *f1)) {
26 return false;
27 }
28 }
29 return (f1 == l1) and (f2 != l2);
30}
31
32/// \ingroup algorithm
33template <typename InputIt1, typename InputIt2>
34[[nodiscard]] constexpr auto lexicographical_compare(InputIt1 f1, InputIt1 l1, InputIt2 f2, InputIt2 l2) -> bool
35{
36 return etl::lexicographical_compare(f1, l1, f2, l2, etl::less());
37}
38
39} // namespace etl
40
41#endif // TETL_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
constexpr auto lexicographical_compare(InputIt1 f1, InputIt1 l1, InputIt2 f2, InputIt2 l2) -> bool
Definition lexicographical_compare.hpp:34
constexpr auto lexicographical_compare(InputIt1 f1, InputIt1 l1, InputIt2 f2, InputIt2 l2, Compare comp) -> bool
Checks if the first range [f1, l1) is lexicographically less than the second range [f2,...
Definition lexicographical_compare.hpp:18
Definition adjacent_find.hpp:9
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15