1bf20a097SArthur O'Dwyer //===----------------------------------------------------------------------===// 2bf20a097SArthur O'Dwyer // 3bf20a097SArthur O'Dwyer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4bf20a097SArthur O'Dwyer // See https://llvm.org/LICENSE.txt for license information. 5bf20a097SArthur O'Dwyer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6bf20a097SArthur O'Dwyer // 7bf20a097SArthur O'Dwyer //===----------------------------------------------------------------------===// 8bf20a097SArthur O'Dwyer 9bf20a097SArthur O'Dwyer #ifndef _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK 10bf20a097SArthur O'Dwyer #define _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK 11bf20a097SArthur O'Dwyer 12bf20a097SArthur O'Dwyer #include <__compare/ordering.h> 13bf20a097SArthur O'Dwyer #include <__compare/weak_order.h> 14*557f7e13SA. Jiang #include <__concepts/boolean_testable.h> 15bf20a097SArthur O'Dwyer #include <__config> 16e0a66116SNikolas Klauser #include <__type_traits/decay.h> 17e0a66116SNikolas Klauser #include <__type_traits/is_same.h> 18bf20a097SArthur O'Dwyer #include <__utility/forward.h> 19bf20a097SArthur O'Dwyer #include <__utility/priority_tag.h> 20bf20a097SArthur O'Dwyer 21bf20a097SArthur O'Dwyer #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 22bf20a097SArthur O'Dwyer # pragma GCC system_header 23bf20a097SArthur O'Dwyer #endif 24bf20a097SArthur O'Dwyer 25bf20a097SArthur O'Dwyer _LIBCPP_BEGIN_NAMESPACE_STD 26bf20a097SArthur O'Dwyer 274f15267dSNikolas Klauser #if _LIBCPP_STD_VER >= 20 28bf20a097SArthur O'Dwyer 29bf20a097SArthur O'Dwyer // [cmp.alg] 30bf20a097SArthur O'Dwyer namespace __compare_weak_order_fallback { 31bf20a097SArthur O'Dwyer struct __fn { 32bf20a097SArthur O'Dwyer template <class _Tp, class _Up> 33bf20a097SArthur O'Dwyer requires is_same_v<decay_t<_Tp>, decay_t<_Up>> 349783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept( 359783f28cSLouis Dionne noexcept(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) 369783f28cSLouis Dionne -> decltype(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))) { 379783f28cSLouis Dionne return std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)); 389783f28cSLouis Dionne } 39bf20a097SArthur O'Dwyer 40bf20a097SArthur O'Dwyer template <class _Tp, class _Up> 41*557f7e13SA. Jiang requires is_same_v<decay_t<_Tp>, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) { 42*557f7e13SA. Jiang { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable; 43*557f7e13SA. Jiang { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable; 44*557f7e13SA. Jiang } 45*557f7e13SA. Jiang _LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept( 469783f28cSLouis Dionne std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent 479783f28cSLouis Dionne : std::forward<_Tp>(__t) < std::forward<_Up>(__u) 489783f28cSLouis Dionne ? weak_ordering::less 49*557f7e13SA. Jiang : weak_ordering::greater)) { 509783f28cSLouis Dionne return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent 519783f28cSLouis Dionne : std::forward<_Tp>(__t) < std::forward<_Up>(__u) 529783f28cSLouis Dionne ? weak_ordering::less 539783f28cSLouis Dionne : weak_ordering::greater; 54bf20a097SArthur O'Dwyer } 55bf20a097SArthur O'Dwyer 56bf20a097SArthur O'Dwyer template <class _Tp, class _Up> 57bf20a097SArthur O'Dwyer _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const 5877a00c0dSLouis Dionne noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>()))) 599783f28cSLouis Dionne -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())) { 609783f28cSLouis Dionne return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>()); 619783f28cSLouis Dionne } 62bf20a097SArthur O'Dwyer }; 63bf20a097SArthur O'Dwyer } // namespace __compare_weak_order_fallback 64bf20a097SArthur O'Dwyer 65bf20a097SArthur O'Dwyer inline namespace __cpo { 66bf20a097SArthur O'Dwyer inline constexpr auto compare_weak_order_fallback = __compare_weak_order_fallback::__fn{}; 67bf20a097SArthur O'Dwyer } // namespace __cpo 68bf20a097SArthur O'Dwyer 694f15267dSNikolas Klauser #endif // _LIBCPP_STD_VER >= 20 70bf20a097SArthur O'Dwyer 71bf20a097SArthur O'Dwyer _LIBCPP_END_NAMESPACE_STD 72bf20a097SArthur O'Dwyer 73bf20a097SArthur O'Dwyer #endif // _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK 74