| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H |
| 10 | #define _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H |
| 11 | |
| 12 | #include <__compare/common_comparison_category.h> |
| 13 | #include <__compare/ordering.h> |
| 14 | #include <__concepts/common_reference_with.h> |
| 15 | #include <__concepts/equality_comparable.h> |
| 16 | #include <__concepts/same_as.h> |
| 17 | #include <__concepts/totally_ordered.h> |
| 18 | #include <__config> |
| 19 | #include <__type_traits/common_reference.h> |
| 20 | #include <__type_traits/make_const_lvalue_ref.h> |
| 21 | |
| 22 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 23 | # pragma GCC system_header |
| 24 | #endif |
| 25 | |
| 26 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 27 | |
| 28 | #if _LIBCPP_STD_VER >= 20 |
| 29 | |
| 30 | template <class _Tp, class _Cat> |
| 31 | concept __compares_as = same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>; |
| 32 | |
| 33 | template <class _Tp, class _Cat = partial_ordering> |
| 34 | concept three_way_comparable = |
| 35 | __weakly_equality_comparable_with<_Tp, _Tp> && __partially_ordered_with<_Tp, _Tp> && |
| 36 | requires(__make_const_lvalue_ref<_Tp> __a, __make_const_lvalue_ref<_Tp> __b) { |
| 37 | { __a <=> __b } -> __compares_as<_Cat>; |
| 38 | }; |
| 39 | |
| 40 | template <class _Tp, class _Up, class _Cat = partial_ordering> |
| 41 | concept three_way_comparable_with = |
| 42 | three_way_comparable<_Tp, _Cat> && three_way_comparable<_Up, _Cat> && |
| 43 | common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> && |
| 44 | three_way_comparable<common_reference_t<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>>, _Cat> && |
| 45 | __weakly_equality_comparable_with<_Tp, _Up> && __partially_ordered_with<_Tp, _Up> && |
| 46 | requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) { |
| 47 | { __t <=> __u } -> __compares_as<_Cat>; |
| 48 | { __u <=> __t } -> __compares_as<_Cat>; |
| 49 | }; |
| 50 | |
| 51 | #endif // _LIBCPP_STD_VER >= 20 |
| 52 | |
| 53 | _LIBCPP_END_NAMESPACE_STD |
| 54 | |
| 55 | #endif // _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H |
| 56 | |