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
3#ifndef TETL_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
4#define TETL_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
5
7
8namespace etl {
9
16template <typename InputIt1, typename InputIt2, typename Compare>
17[[nodiscard]] constexpr auto lexicographical_compare(InputIt1 f1, InputIt1 l1, InputIt2 f2, InputIt2 l2, Compare comp)
18 -> bool
19{
20 for (; (f1 != l1) and (f2 != l2); ++f1, (void)++f2) {
21 if (comp(*f1, *f2)) {
22 return true;
23 }
24 if (comp(*f2, *f1)) {
25 return false;
26 }
27 }
28 return (f1 == l1) and (f2 != l2);
29}
30
32template <typename InputIt1, typename InputIt2>
33[[nodiscard]] constexpr auto lexicographical_compare(InputIt1 f1, InputIt1 l1, InputIt2 f2, InputIt2 l2) -> bool
34{
35 return etl::lexicographical_compare(f1, l1, f2, l2, etl::less());
36}
37
38} // namespace etl
39
40#endif // TETL_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
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:17
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14