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