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_COMPARE_PARTIAL_ORDER_FALLBACK 10 #define _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK 11 12 #include <__compare/ordering.h> 13 #include <__compare/partial_order.h> 14 #include <__config> 15 #include <__type_traits/decay.h> 16 #include <__type_traits/is_same.h> 17 #include <__utility/forward.h> 18 #include <__utility/priority_tag.h> 19 20 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 21 # pragma GCC system_header 22 #endif 23 24 _LIBCPP_BEGIN_NAMESPACE_STD 25 26 #if _LIBCPP_STD_VER >= 20 27 28 // [cmp.alg] 29 namespace __compare_partial_order_fallback { 30 struct __fn { 31 template<class _Tp, class _Up> 32 requires is_same_v<decay_t<_Tp>, decay_t<_Up>> 33 _LIBCPP_HIDE_FROM_ABI static constexpr auto 34 __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) 35 noexcept(noexcept(_VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))) 36 -> decltype( _VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))) 37 { return _VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); } 38 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(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent : 44 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less : 45 _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater : 46 partial_ordering::unordered)) 47 -> decltype( _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent : 48 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less : 49 _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater : 50 partial_ordering::unordered) 51 { 52 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent : 53 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less : 54 _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater : 55 partial_ordering::unordered; 56 } 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<1>()))) 61 -> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())) 62 { return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); } 63 }; 64 } // namespace __compare_partial_order_fallback 65 66 inline namespace __cpo { 67 inline constexpr auto compare_partial_order_fallback = __compare_partial_order_fallback::__fn{}; 68 } // namespace __cpo 69 70 #endif // _LIBCPP_STD_VER >= 20 71 72 _LIBCPP_END_NAMESPACE_STD 73 74 #endif // _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK 75