14824e7fdSDimitry Andric //===----------------------------------------------------------------------===// 24824e7fdSDimitry Andric // 34824e7fdSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 44824e7fdSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 54824e7fdSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 64824e7fdSDimitry Andric // 74824e7fdSDimitry Andric //===----------------------------------------------------------------------===// 84824e7fdSDimitry Andric 94824e7fdSDimitry Andric #ifndef _LIBCPP___COMPARE_PARTIAL_ORDER 104824e7fdSDimitry Andric #define _LIBCPP___COMPARE_PARTIAL_ORDER 114824e7fdSDimitry Andric 124824e7fdSDimitry Andric #include <__compare/compare_three_way.h> 134824e7fdSDimitry Andric #include <__compare/ordering.h> 144824e7fdSDimitry Andric #include <__compare/weak_order.h> 154824e7fdSDimitry Andric #include <__config> 16bdd1243dSDimitry Andric #include <__type_traits/decay.h> 17bdd1243dSDimitry Andric #include <__type_traits/is_same.h> 184824e7fdSDimitry Andric #include <__utility/forward.h> 194824e7fdSDimitry Andric #include <__utility/priority_tag.h> 204824e7fdSDimitry Andric 214824e7fdSDimitry Andric #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 224824e7fdSDimitry Andric # pragma GCC system_header 234824e7fdSDimitry Andric #endif 244824e7fdSDimitry Andric 254824e7fdSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 264824e7fdSDimitry Andric 2706c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 284824e7fdSDimitry Andric 294824e7fdSDimitry Andric // [cmp.alg] 304824e7fdSDimitry Andric namespace __partial_order { 31*0fca6ea1SDimitry Andric void partial_order() = delete; 32*0fca6ea1SDimitry Andric 334824e7fdSDimitry Andric struct __fn { 34bdd1243dSDimitry Andric // NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, but only here 354824e7fdSDimitry Andric template <class _Tp, class _Up> 364824e7fdSDimitry Andric requires is_same_v<decay_t<_Tp>, decay_t<_Up>> 37cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept( 38cb14a3feSDimitry Andric noexcept(partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) 39cb14a3feSDimitry Andric -> decltype(partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { 40cb14a3feSDimitry Andric return partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))); 41cb14a3feSDimitry Andric } 42bdd1243dSDimitry Andric // NOLINTEND(libcpp-robust-against-adl) 434824e7fdSDimitry Andric 444824e7fdSDimitry Andric template <class _Tp, class _Up> 454824e7fdSDimitry Andric requires is_same_v<decay_t<_Tp>, decay_t<_Up>> 46cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept( 47cb14a3feSDimitry Andric noexcept(partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) 48cb14a3feSDimitry Andric -> decltype(partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { 49cb14a3feSDimitry Andric return partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u))); 50cb14a3feSDimitry Andric } 514824e7fdSDimitry Andric 524824e7fdSDimitry Andric template <class _Tp, class _Up> 534824e7fdSDimitry Andric requires is_same_v<decay_t<_Tp>, decay_t<_Up>> 54cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept( 55cb14a3feSDimitry Andric noexcept(partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) 56cb14a3feSDimitry Andric -> decltype(partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { 57cb14a3feSDimitry Andric return partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))); 58cb14a3feSDimitry Andric } 594824e7fdSDimitry Andric 604824e7fdSDimitry Andric template <class _Tp, class _Up> 614824e7fdSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const 625f757f3fSDimitry Andric noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>()))) 63cb14a3feSDimitry Andric -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>())) { 64cb14a3feSDimitry Andric return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>()); 65cb14a3feSDimitry Andric } 664824e7fdSDimitry Andric }; 674824e7fdSDimitry Andric } // namespace __partial_order 684824e7fdSDimitry Andric 694824e7fdSDimitry Andric inline namespace __cpo { 704824e7fdSDimitry Andric inline constexpr auto partial_order = __partial_order::__fn{}; 714824e7fdSDimitry Andric } // namespace __cpo 724824e7fdSDimitry Andric 7306c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 744824e7fdSDimitry Andric 754824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD 764824e7fdSDimitry Andric 774824e7fdSDimitry Andric #endif // _LIBCPP___COMPARE_PARTIAL_ORDER 78