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_WEAK_ORDER_FALLBACK
10 #define _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK
11 
12 #include <__compare/ordering.h>
13 #include <__compare/weak_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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
26 
27 // [cmp.alg]
28 namespace __compare_weak_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::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
35             -> decltype(      _VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
36             { return          _VSTD::weak_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) ? weak_ordering::equivalent :
43                               _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
44                               weak_ordering::greater))
45             -> decltype(      _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
46                               _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
47                               weak_ordering::greater)
48         {
49             return            _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
50                               _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
51                               weak_ordering::greater;
52         }
53 
54         template<class _Tp, class _Up>
55         _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
56             noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
57             -> decltype(      __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
58             { return          __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
59     };
60 } // namespace __compare_weak_order_fallback
61 
62 inline namespace __cpo {
63     inline constexpr auto compare_weak_order_fallback = __compare_weak_order_fallback::__fn{};
64 } // namespace __cpo
65 
66 #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
67 
68 _LIBCPP_END_NAMESPACE_STD
69 
70 #endif // _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK
71