76 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_COMPARE_PARTIAL_ORDER_FALLBACK10#define _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK11 12#include <__compare/ordering.h>13#include <__compare/partial_order.h>14#include <__concepts/boolean_testable.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 __compare_partial_order_fallback {31struct __fn {32 template <class _Tp, class _Up>33 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>34 _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept(35 noexcept(std::partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))36 -> decltype(std::partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))) {37 return std::partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u));38 }39 40 template <class _Tp, class _Up>41 requires is_same_v<decay_t<_Tp>, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) {42 { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable;43 { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable;44 { std::forward<_Up>(__u) < std::forward<_Tp>(__t) } -> __boolean_testable;45 }46 _LIBCPP_HIDE_FROM_ABI static constexpr partial_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(47 noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent48 : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less49 : std::forward<_Up>(__u) < std::forward<_Tp>(__t) ? partial_ordering::greater50 : partial_ordering::unordered)) {51 return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent52 : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less53 : std::forward<_Up>(__u) < std::forward<_Tp>(__t)54 ? partial_ordering::greater55 : partial_ordering::unordered;56 }57 58 template <class _Tp, class _Up>59 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const60 noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())))61 -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())) {62 return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>());63 }64};65} // namespace __compare_partial_order_fallback66 67inline namespace __cpo {68inline constexpr auto compare_partial_order_fallback = __compare_partial_order_fallback::__fn{};69} // namespace __cpo70 71#endif // _LIBCPP_STD_VER >= 2072 73_LIBCPP_END_NAMESPACE_STD74 75#endif // _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK76