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