Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:26

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___COMPARE_WEAK_ORDER
0010 #define _LIBCPP___CXX03___COMPARE_WEAK_ORDER
0011 
0012 #include <__cxx03/__compare/compare_three_way.h>
0013 #include <__cxx03/__compare/ordering.h>
0014 #include <__cxx03/__compare/strong_order.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__math/traits.h>
0017 #include <__cxx03/__type_traits/decay.h>
0018 #include <__cxx03/__type_traits/is_floating_point.h>
0019 #include <__cxx03/__type_traits/is_same.h>
0020 #include <__cxx03/__utility/forward.h>
0021 #include <__cxx03/__utility/priority_tag.h>
0022 
0023 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028 
0029 #if _LIBCPP_STD_VER >= 20
0030 
0031 // [cmp.alg]
0032 namespace __weak_order {
0033 void weak_order() = delete;
0034 
0035 struct __fn {
0036   // NOLINTBEGIN(libcpp-robust-against-adl) weak_order should use ADL, but only here
0037   template <class _Tp, class _Up>
0038     requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
0039   _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<3>) noexcept(
0040       noexcept(weak_ordering(weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
0041       -> decltype(weak_ordering(weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
0042     return weak_ordering(weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
0043   }
0044   // NOLINTEND(libcpp-robust-against-adl)
0045 
0046   template <class _Tp, class _Up, class _Dp = decay_t<_Tp>>
0047     requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp>
0048   _LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept {
0049     partial_ordering __po = (__t <=> __u);
0050     if (__po == partial_ordering::less) {
0051       return weak_ordering::less;
0052     } else if (__po == partial_ordering::equivalent) {
0053       return weak_ordering::equivalent;
0054     } else if (__po == partial_ordering::greater) {
0055       return weak_ordering::greater;
0056     } else {
0057       // Otherwise, at least one of them is a NaN.
0058       bool __t_is_nan      = __math::isnan(__t);
0059       bool __u_is_nan      = __math::isnan(__u);
0060       bool __t_is_negative = __math::signbit(__t);
0061       bool __u_is_negative = __math::signbit(__u);
0062       if (__t_is_nan && __u_is_nan) {
0063         return (__u_is_negative <=> __t_is_negative);
0064       } else if (__t_is_nan) {
0065         return __t_is_negative ? weak_ordering::less : weak_ordering::greater;
0066       } else {
0067         return __u_is_negative ? weak_ordering::greater : weak_ordering::less;
0068       }
0069     }
0070   }
0071 
0072   template <class _Tp, class _Up>
0073     requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
0074   _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept(
0075       noexcept(weak_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
0076       -> decltype(weak_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
0077     return weak_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
0078   }
0079 
0080   template <class _Tp, class _Up>
0081     requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
0082   _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(
0083       noexcept(weak_ordering(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
0084       -> decltype(weak_ordering(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
0085     return weak_ordering(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
0086   }
0087 
0088   template <class _Tp, class _Up>
0089   _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
0090       noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<3>())))
0091           -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<3>())) {
0092     return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<3>());
0093   }
0094 };
0095 } // namespace __weak_order
0096 
0097 inline namespace __cpo {
0098 inline constexpr auto weak_order = __weak_order::__fn{};
0099 } // namespace __cpo
0100 
0101 #endif // _LIBCPP_STD_VER >= 20
0102 
0103 _LIBCPP_END_NAMESPACE_STD
0104 
0105 #endif // _LIBCPP___CXX03___COMPARE_WEAK_ORDER