xref: /openbsd-src/gnu/llvm/libcxx/include/__compare/partial_order.h (revision 4bdff4bed0e3d54e55670334c7d0077db4170f86)
1*4bdff4beSrobert //===----------------------------------------------------------------------===//
2*4bdff4beSrobert //
3*4bdff4beSrobert // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*4bdff4beSrobert // See https://llvm.org/LICENSE.txt for license information.
5*4bdff4beSrobert // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*4bdff4beSrobert //
7*4bdff4beSrobert //===----------------------------------------------------------------------===//
8*4bdff4beSrobert 
9*4bdff4beSrobert #ifndef _LIBCPP___COMPARE_PARTIAL_ORDER
10*4bdff4beSrobert #define _LIBCPP___COMPARE_PARTIAL_ORDER
11*4bdff4beSrobert 
12*4bdff4beSrobert #include <__compare/compare_three_way.h>
13*4bdff4beSrobert #include <__compare/ordering.h>
14*4bdff4beSrobert #include <__compare/weak_order.h>
15*4bdff4beSrobert #include <__config>
16*4bdff4beSrobert #include <__type_traits/decay.h>
17*4bdff4beSrobert #include <__type_traits/is_same.h>
18*4bdff4beSrobert #include <__utility/forward.h>
19*4bdff4beSrobert #include <__utility/priority_tag.h>
20*4bdff4beSrobert 
21*4bdff4beSrobert #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
22*4bdff4beSrobert #  pragma GCC system_header
23*4bdff4beSrobert #endif
24*4bdff4beSrobert 
25*4bdff4beSrobert _LIBCPP_BEGIN_NAMESPACE_STD
26*4bdff4beSrobert 
27*4bdff4beSrobert #if _LIBCPP_STD_VER > 17
28*4bdff4beSrobert 
29*4bdff4beSrobert // [cmp.alg]
30*4bdff4beSrobert namespace __partial_order {
31*4bdff4beSrobert     struct __fn {
32*4bdff4beSrobert     // NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, but only here
33*4bdff4beSrobert         template<class _Tp, class _Up>
34*4bdff4beSrobert             requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
35*4bdff4beSrobert         _LIBCPP_HIDE_FROM_ABI static constexpr auto
36*4bdff4beSrobert         __go(_Tp&& __t, _Up&& __u, __priority_tag<2>)
37*4bdff4beSrobert             noexcept(noexcept(partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
38*4bdff4beSrobert             -> decltype(      partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
39*4bdff4beSrobert             { return          partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
40*4bdff4beSrobert     // NOLINTEND(libcpp-robust-against-adl)
41*4bdff4beSrobert 
42*4bdff4beSrobert         template<class _Tp, class _Up>
43*4bdff4beSrobert             requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
44*4bdff4beSrobert         _LIBCPP_HIDE_FROM_ABI static constexpr auto
45*4bdff4beSrobert         __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
46*4bdff4beSrobert             noexcept(noexcept(partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
47*4bdff4beSrobert             -> decltype(      partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
48*4bdff4beSrobert             { return          partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
49*4bdff4beSrobert 
50*4bdff4beSrobert         template<class _Tp, class _Up>
51*4bdff4beSrobert             requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
52*4bdff4beSrobert         _LIBCPP_HIDE_FROM_ABI static constexpr auto
53*4bdff4beSrobert         __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
54*4bdff4beSrobert             noexcept(noexcept(partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
55*4bdff4beSrobert             -> decltype(      partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
56*4bdff4beSrobert             { return          partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
57*4bdff4beSrobert 
58*4bdff4beSrobert         template<class _Tp, class _Up>
59*4bdff4beSrobert         _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
60*4bdff4beSrobert             noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>())))
61*4bdff4beSrobert             -> decltype(      __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()))
62*4bdff4beSrobert             { return          __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()); }
63*4bdff4beSrobert     };
64*4bdff4beSrobert } // namespace __partial_order
65*4bdff4beSrobert 
66*4bdff4beSrobert inline namespace __cpo {
67*4bdff4beSrobert     inline constexpr auto partial_order = __partial_order::__fn{};
68*4bdff4beSrobert } // namespace __cpo
69*4bdff4beSrobert 
70*4bdff4beSrobert #endif // _LIBCPP_STD_VER > 17
71*4bdff4beSrobert 
72*4bdff4beSrobert _LIBCPP_END_NAMESPACE_STD
73*4bdff4beSrobert 
74*4bdff4beSrobert #endif // _LIBCPP___COMPARE_PARTIAL_ORDER
75