File indexing completed on 2025-12-15 10:11:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef CPP_COMPARE_HPP
0018 #define CPP_COMPARE_HPP
0019
0020 #if __cplusplus > 201703L && __has_include(<compare>) && \
0021 defined(__cpp_concepts) && defined(__cpp_impl_three_way_comparison)
0022
0023 #include <compare>
0024 #include <concepts/concepts.hpp>
0025 #include <range/v3/compare.hpp>
0026
0027
0028
0029 namespace concepts
0030 {
0031
0032
0033 namespace detail
0034 {
0035 template<typename T, typename Cat>
0036 concept compares_as = same_as<ranges::common_comparison_category_t<T, Cat>, Cat>;
0037 }
0038
0039 inline namespace defs
0040 {
0041 template<typename T, typename Cat = std::partial_ordering>
0042 concept three_way_comparable =
0043 detail::weakly_equality_comparable_with_<T, T> &&
0044 detail::partially_ordered_with_<T ,T> &&
0045 requires(detail::as_cref_t<T>& a, detail::as_cref_t<T>& b) {
0046 { a <=> b } -> detail::compares_as<Cat>;
0047 };
0048
0049 template<typename T, typename U, typename Cat = std::partial_ordering>
0050 concept three_way_comparable_with =
0051 three_way_comparable<T, Cat> &&
0052 three_way_comparable<U, Cat> &&
0053 common_reference_with<detail::as_cref_t<T>&, detail::as_cref_t<U>&> &&
0054 three_way_comparable<common_reference_t<detail::as_cref_t<T>&, detail::as_cref_t<U>&>> &&
0055 detail::partially_ordered_with_<T, U> &&
0056 requires(detail::as_cref_t<T>& t, detail::as_cref_t<U>& u) {
0057 { t <=> u } -> detail::compares_as<Cat>;
0058 { u <=> t } -> detail::compares_as<Cat>;
0059 };
0060 }
0061 }
0062
0063
0064
0065 #endif
0066 #endif