totally_ordered.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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___CONCEPTS_TOTALLY_ORDERED_H
  9. #define _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H
  10. #include <__concepts/boolean_testable.h>
  11. #include <__concepts/equality_comparable.h>
  12. #include <__config>
  13. #include <__type_traits/common_reference.h>
  14. #include <__type_traits/make_const_lvalue_ref.h>
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. # pragma GCC system_header
  17. #endif
  18. _LIBCPP_BEGIN_NAMESPACE_STD
  19. #if _LIBCPP_STD_VER >= 20
  20. // [concept.totallyordered]
  21. template <class _Tp, class _Up>
  22. concept __partially_ordered_with = requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
  23. { __t < __u } -> __boolean_testable;
  24. { __t > __u } -> __boolean_testable;
  25. { __t <= __u } -> __boolean_testable;
  26. { __t >= __u } -> __boolean_testable;
  27. { __u < __t } -> __boolean_testable;
  28. { __u > __t } -> __boolean_testable;
  29. { __u <= __t } -> __boolean_testable;
  30. { __u >= __t } -> __boolean_testable;
  31. };
  32. template <class _Tp>
  33. concept totally_ordered = equality_comparable<_Tp> && __partially_ordered_with<_Tp, _Tp>;
  34. // clang-format off
  35. template <class _Tp, class _Up>
  36. concept totally_ordered_with =
  37. totally_ordered<_Tp> && totally_ordered<_Up> &&
  38. equality_comparable_with<_Tp, _Up> &&
  39. totally_ordered<
  40. common_reference_t<
  41. __make_const_lvalue_ref<_Tp>,
  42. __make_const_lvalue_ref<_Up>>> &&
  43. __partially_ordered_with<_Tp, _Up>;
  44. // clang-format on
  45. #endif // _LIBCPP_STD_VER >= 20
  46. _LIBCPP_END_NAMESPACE_STD
  47. #endif // _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H