three_way_comparable.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #ifndef _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H
  9. #define _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H
  10. #include <__compare/common_comparison_category.h>
  11. #include <__compare/ordering.h>
  12. #include <__concepts/common_reference_with.h>
  13. #include <__concepts/equality_comparable.h>
  14. #include <__concepts/same_as.h>
  15. #include <__concepts/totally_ordered.h>
  16. #include <__config>
  17. #include <type_traits>
  18. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  19. # pragma GCC system_header
  20. #endif
  21. _LIBCPP_BEGIN_NAMESPACE_STD
  22. #if !defined(_LIBCPP_HAS_NO_CONCEPTS)
  23. template<class _Tp, class _Cat>
  24. concept __compares_as =
  25. same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>;
  26. template<class _Tp, class _Cat = partial_ordering>
  27. concept three_way_comparable =
  28. __weakly_equality_comparable_with<_Tp, _Tp> &&
  29. __partially_ordered_with<_Tp, _Tp> &&
  30. requires(__make_const_lvalue_ref<_Tp> __a, __make_const_lvalue_ref<_Tp> __b) {
  31. { __a <=> __b } -> __compares_as<_Cat>;
  32. };
  33. template<class _Tp, class _Up, class _Cat = partial_ordering>
  34. concept three_way_comparable_with =
  35. three_way_comparable<_Tp, _Cat> &&
  36. three_way_comparable<_Up, _Cat> &&
  37. common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
  38. three_way_comparable<common_reference_t<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>>, _Cat> &&
  39. __weakly_equality_comparable_with<_Tp, _Up> &&
  40. __partially_ordered_with<_Tp, _Up> &&
  41. requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
  42. { __t <=> __u } -> __compares_as<_Cat>;
  43. { __u <=> __t } -> __compares_as<_Cat>;
  44. };
  45. #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
  46. _LIBCPP_END_NAMESPACE_STD
  47. #endif // _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H