partial_order.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <__type_traits/decay.h>
  15. #include <__type_traits/is_same.h>
  16. #include <__utility/forward.h>
  17. #include <__utility/priority_tag.h>
  18. #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
  19. # pragma GCC system_header
  20. #endif
  21. _LIBCPP_BEGIN_NAMESPACE_STD
  22. #if _LIBCPP_STD_VER >= 20
  23. // [cmp.alg]
  24. namespace __partial_order {
  25. struct __fn {
  26. // NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, but only here
  27. template<class _Tp, class _Up>
  28. requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
  29. _LIBCPP_HIDE_FROM_ABI static constexpr auto
  30. __go(_Tp&& __t, _Up&& __u, __priority_tag<2>)
  31. noexcept(noexcept(partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
  32. -> decltype( partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
  33. { return partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
  34. // NOLINTEND(libcpp-robust-against-adl)
  35. template<class _Tp, class _Up>
  36. requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
  37. _LIBCPP_HIDE_FROM_ABI static constexpr auto
  38. __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
  39. noexcept(noexcept(partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
  40. -> decltype( partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
  41. { return partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
  42. template<class _Tp, class _Up>
  43. requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
  44. _LIBCPP_HIDE_FROM_ABI static constexpr auto
  45. __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
  46. noexcept(noexcept(partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
  47. -> decltype( partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
  48. { return partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
  49. template<class _Tp, class _Up>
  50. _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
  51. noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>())))
  52. -> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()))
  53. { return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()); }
  54. };
  55. } // namespace __partial_order
  56. inline namespace __cpo {
  57. inline constexpr auto partial_order = __partial_order::__fn{};
  58. } // namespace __cpo
  59. #endif // _LIBCPP_STD_VER >= 20
  60. _LIBCPP_END_NAMESPACE_STD
  61. #endif // _LIBCPP___COMPARE_PARTIAL_ORDER