partial_order.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_PARTIAL_ORDER
  9. #define _LIBCPP___COMPARE_PARTIAL_ORDER
  10. #include <__compare/compare_three_way.h>
  11. #include <__compare/ordering.h>
  12. #include <__compare/weak_order.h>
  13. #include <__config>
  14. #include <__utility/forward.h>
  15. #include <__utility/priority_tag.h>
  16. #include <type_traits>
  17. #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
  18. # pragma GCC system_header
  19. #endif
  20. _LIBCPP_BEGIN_NAMESPACE_STD
  21. #if !defined(_LIBCPP_HAS_NO_CONCEPTS)
  22. // [cmp.alg]
  23. namespace __partial_order {
  24. struct __fn {
  25. template<class _Tp, class _Up>
  26. requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
  27. _LIBCPP_HIDE_FROM_ABI static constexpr auto
  28. __go(_Tp&& __t, _Up&& __u, __priority_tag<2>)
  29. noexcept(noexcept(partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
  30. -> decltype( partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
  31. { return partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
  32. template<class _Tp, class _Up>
  33. requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
  34. _LIBCPP_HIDE_FROM_ABI static constexpr auto
  35. __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
  36. noexcept(noexcept(partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
  37. -> decltype( partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
  38. { return partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
  39. template<class _Tp, class _Up>
  40. requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
  41. _LIBCPP_HIDE_FROM_ABI static constexpr auto
  42. __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
  43. noexcept(noexcept(partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
  44. -> decltype( partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
  45. { return partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
  46. template<class _Tp, class _Up>
  47. _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
  48. noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>())))
  49. -> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()))
  50. { return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()); }
  51. };
  52. } // namespace __partial_order
  53. inline namespace __cpo {
  54. inline constexpr auto partial_order = __partial_order::__fn{};
  55. } // namespace __cpo
  56. #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
  57. _LIBCPP_END_NAMESPACE_STD
  58. #endif // _LIBCPP___COMPARE_PARTIAL_ORDER