78 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___COMPARE_PARTIAL_ORDER10#define _LIBCPP___COMPARE_PARTIAL_ORDER11 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_HEADER22# pragma GCC system_header23#endif24 25_LIBCPP_BEGIN_NAMESPACE_STD26 27#if _LIBCPP_STD_VER >= 2028 29// [cmp.alg]30namespace __partial_order {31void partial_order() = delete;32 33struct __fn {34 // NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, but only here35 template <class _Tp, class _Up>36 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>37 _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept(38 noexcept(partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))39 -> decltype(partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {40 return partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)));41 }42 // NOLINTEND(libcpp-robust-against-adl)43 44 template <class _Tp, class _Up>45 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>46 _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept(47 noexcept(partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))48 -> decltype(partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {49 return partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)));50 }51 52 template <class _Tp, class _Up>53 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>54 _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(55 noexcept(partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))56 -> decltype(partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {57 return partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)));58 }59 60 template <class _Tp, class _Up>61 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const62 noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>())))63 -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>())) {64 return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>());65 }66};67} // namespace __partial_order68 69inline namespace __cpo {70inline constexpr auto partial_order = __partial_order::__fn{};71} // namespace __cpo72 73#endif // _LIBCPP_STD_VER >= 2074 75_LIBCPP_END_NAMESPACE_STD76 77#endif // _LIBCPP___COMPARE_PARTIAL_ORDER78