| 1 |
/// \file |
| 2 |
// Range v3 library |
| 3 |
// |
| 4 |
// Copyright Eric Niebler 2013-present |
| 5 |
// Copyright Casey Carter 2016 |
| 6 |
// |
| 7 |
// Use, modification and distribution is subject to the |
| 8 |
// Boost Software License, Version 1.0. (See accompanying |
| 9 |
// file LICENSE_1_0.txt or copy at |
| 10 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 11 |
// |
| 12 |
// Project home: https://github.com/ericniebler/range-v3 |
| 13 |
// |
| 14 |
#ifndef RANGES_V3_FUNCTIONAL_COMPARISONS_HPP |
| 15 |
#define RANGES_V3_FUNCTIONAL_COMPARISONS_HPP |
| 16 |
|
| 17 |
#include <concepts/concepts.hpp> |
| 18 |
|
| 19 |
#include <range/v3/range_fwd.hpp> |
| 20 |
|
| 21 |
#include <range/v3/detail/prologue.hpp> |
| 22 |
|
| 23 |
namespace ranges |
| 24 |
{ |
| 25 |
/// \addtogroup group-functional |
| 26 |
/// @{ |
| 27 |
struct equal_to |
| 28 |
{ |
| 29 |
template(typename T, typename U)( |
| 30 |
requires equality_comparable_with<T, U>) |
| 31 |
constexpr bool operator()(T && t, U && u) const |
| 32 |
{ |
| 33 |
return (T &&) t == (U &&) u; |
| 34 |
} |
| 35 |
using is_transparent = void; |
| 36 |
}; |
| 37 |
|
| 38 |
struct not_equal_to |
| 39 |
{ |
| 40 |
template(typename T, typename U)( |
| 41 |
requires equality_comparable_with<T, U>) |
| 42 |
constexpr bool operator()(T && t, U && u) const |
| 43 |
{ |
| 44 |
return !equal_to{}((T &&) t, (U &&) u); |
| 45 |
} |
| 46 |
using is_transparent = void; |
| 47 |
}; |
| 48 |
|
| 49 |
struct less |
| 50 |
{ |
| 51 |
template(typename T, typename U)( |
| 52 |
requires totally_ordered_with<T, U>) |
| 53 |
constexpr bool operator()(T && t, U && u) const |
| 54 |
{ |
| 55 |
return (T &&) t < (U &&) u; |
| 56 |
} |
| 57 |
using is_transparent = void; |
| 58 |
}; |
| 59 |
|
| 60 |
struct less_equal |
| 61 |
{ |
| 62 |
template(typename T, typename U)( |
| 63 |
requires totally_ordered_with<T, U>) |
| 64 |
constexpr bool operator()(T && t, U && u) const |
| 65 |
{ |
| 66 |
return !less{}((U &&) u, (T &&) t); |
| 67 |
} |
| 68 |
using is_transparent = void; |
| 69 |
}; |
| 70 |
|
| 71 |
struct greater_equal |
| 72 |
{ |
| 73 |
template(typename T, typename U)( |
| 74 |
requires totally_ordered_with<T, U>) |
| 75 |
constexpr bool operator()(T && t, U && u) const |
| 76 |
{ |
| 77 |
return !less{}((T &&) t, (U &&) u); |
| 78 |
} |
| 79 |
using is_transparent = void; |
| 80 |
}; |
| 81 |
|
| 82 |
struct greater |
| 83 |
{ |
| 84 |
template(typename T, typename U)( |
| 85 |
requires totally_ordered_with<T, U>) |
| 86 |
constexpr bool operator()(T && t, U && u) const |
| 87 |
{ |
| 88 |
return less{}((U &&) u, (T &&) t); |
| 89 |
} |
| 90 |
using is_transparent = void; |
| 91 |
}; |
| 92 |
|
| 93 |
using ordered_less RANGES_DEPRECATED( |
| 94 |
"Repace uses of ranges::ordered_less with ranges::less") = less; |
| 95 |
|
| 96 |
#if __cplusplus > 201703L && __has_include(<compare>) && \ |
| 97 |
defined(__cpp_concepts) && defined(__cpp_impl_three_way_comparison) |
| 98 |
struct compare_three_way |
| 99 |
{ |
| 100 |
template(typename T, typename U)( |
| 101 |
requires three_way_comparable_with<T, U>) |
| 102 |
constexpr auto operator()(T && t, U && u) const |
| 103 |
-> decltype((T &&) t <=> (U &&) u) |
| 104 |
{ |
| 105 |
return (T &&) t <=> (U &&) u; |
| 106 |
} |
| 107 |
|
| 108 |
using is_transparent = void; |
| 109 |
}; |
| 110 |
#endif // __cplusplus |
| 111 |
|
| 112 |
namespace cpp20 |
| 113 |
{ |
| 114 |
using ranges::equal_to; |
| 115 |
using ranges::greater; |
| 116 |
using ranges::greater_equal; |
| 117 |
using ranges::less; |
| 118 |
using ranges::less_equal; |
| 119 |
using ranges::not_equal_to; |
| 120 |
} // namespace cpp20 |
| 121 |
/// @} |
| 122 |
} // namespace ranges |
| 123 |
|
| 124 |
#include <range/v3/detail/epilogue.hpp> |
| 125 |
|
| 126 |
#endif |