5 #ifndef DUNE_COMMON_STD_ALGORITHM_HH 6 #define DUNE_COMMON_STD_ALGORITHM_HH 9 #if !(__cpp_impl_three_way_comparison >= 201907L && __cpp_lib_concepts && __has_include(<compare>)) 10 #error "Three-way comparison requires language support!" 15 #include <type_traits> 30 #if __cpp_lib_three_way_comparison >= 201907L 34 #else // __cpp_lib_three_way_comparison 36 template <
class I1,
class I2,
class Cmp = Std::compare_three_way>
38 -> decltype(comp(*f1, *f2))
40 using ret_t = decltype(comp(*f1, *f2));
41 static_assert(std::disjunction_v<
42 std::is_same<ret_t, std::strong_ordering>,
43 std::is_same<ret_t, std::weak_ordering>,
44 std::is_same<ret_t, std::partial_ordering>>,
45 "The return type must be a comparison category type.");
47 bool exhaust1 = (f1 == l1);
48 bool exhaust2 = (f2 == l2);
49 for (; !exhaust1 && !exhaust2; exhaust1 = (++f1 == l1), exhaust2 = (++f2 == l2))
50 if (
auto c = comp(*f1, *f2); c != 0)
53 return !exhaust1 ? std::strong_ordering::greater:
54 !exhaust2 ? std::strong_ordering::less:
58 #endif // __cpp_lib_three_way_comparison 62 #endif // DUNE_COMMON_STD_ALGORITHM_HH Namespace for features backported from new C++ standards.
Definition: algorithm.hh:19
constexpr std::is_same< std::integer_sequence< bool, true,(ST(II)==ST(JJ))... >, std::integer_sequence< bool,(ST(II)==ST(JJ))..., true > > equal(std::integer_sequence< S, II... >, std::integer_sequence< T, JJ... >)
Checks whether two sequences are identical.
Definition: integersequence.hh:170
This file provides some concepts introduced in the C++20 standard library <compare> and <concepts> no...
constexpr auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2, Cmp comp={}) -> decltype(comp(*f1, *f2))
Lexicographically compares two ranges [first1, last1) and [first2, last2) using three-way comparison ...
Definition: algorithm.hh:37