totally_ordered.h 1.8 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___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 > 17
  20. // [concept.totallyordered]
  21. template<class _Tp, class _Up>
  22. concept __partially_ordered_with =
  23. requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
  24. { __t < __u } -> __boolean_testable;
  25. { __t > __u } -> __boolean_testable;
  26. { __t <= __u } -> __boolean_testable;
  27. { __t >= __u } -> __boolean_testable;
  28. { __u < __t } -> __boolean_testable;
  29. { __u > __t } -> __boolean_testable;
  30. { __u <= __t } -> __boolean_testable;
  31. { __u >= __t } -> __boolean_testable;
  32. };
  33. template<class _Tp>
  34. concept totally_ordered = equality_comparable<_Tp> && __partially_ordered_with<_Tp, _Tp>;
  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. #endif // _LIBCPP_STD_VER > 17
  45. _LIBCPP_END_NAMESPACE_STD
  46. #endif // _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H