totally_ordered.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. #if !defined(_LIBCPP_HAS_NO_CONCEPTS)
  19. // [concept.totallyordered]
  20. template<class _Tp, class _Up>
  21. concept __partially_ordered_with =
  22. 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. template<class _Tp, class _Up>
  35. concept totally_ordered_with =
  36. totally_ordered<_Tp> && totally_ordered<_Up> &&
  37. equality_comparable_with<_Tp, _Up> &&
  38. totally_ordered<
  39. common_reference_t<
  40. __make_const_lvalue_ref<_Tp>,
  41. __make_const_lvalue_ref<_Up>>> &&
  42. __partially_ordered_with<_Tp, _Up>;
  43. #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
  44. _LIBCPP_END_NAMESPACE_STD
  45. #endif // _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H