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!"
17#include <dune/common/std/compare.hh>
30#if __cpp_lib_three_way_comparison >= 201907L
32using std::lexicographical_compare_three_way;
36template <
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:
55 std::strong_ordering::equal;
Namespace for features backported from new C++ standards.
Definition: algorithm.hh:19
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