Release Cosmopolitan v3.6.0

This release is an atomic upgrade to GCC 14.1.0 with C23 and C++23
This commit is contained in:
Justine Tunney 2024-07-23 03:16:17 -07:00
parent 62ace3623a
commit 5660ec4741
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
1585 changed files with 117353 additions and 271644 deletions

View file

@ -24,17 +24,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace __comp_detail {
enum _ClassifyCompCategory : unsigned {
_None,
_PartialOrd,
_WeakOrd,
_StrongOrd,
_CCC_Size
};
enum _ClassifyCompCategory : unsigned { _None, _PartialOrd, _WeakOrd, _StrongOrd, _CCC_Size };
template <class _Tp>
_LIBCPP_HIDE_FROM_ABI
constexpr _ClassifyCompCategory __type_to_enum() noexcept {
_LIBCPP_HIDE_FROM_ABI constexpr _ClassifyCompCategory __type_to_enum() noexcept {
if (is_same_v<_Tp, partial_ordering>)
return _PartialOrd;
if (is_same_v<_Tp, weak_ordering>)
@ -45,8 +38,7 @@ constexpr _ClassifyCompCategory __type_to_enum() noexcept {
}
template <size_t _Size>
_LIBCPP_HIDE_FROM_ABI
constexpr _ClassifyCompCategory
_LIBCPP_HIDE_FROM_ABI constexpr _ClassifyCompCategory
__compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) {
int __seen[_CCC_Size] = {};
for (auto __type : __types)
@ -60,12 +52,11 @@ __compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) {
return _StrongOrd;
}
template <class ..._Ts, bool _False = false>
_LIBCPP_HIDE_FROM_ABI
constexpr auto __get_comp_type() {
using _CCC = _ClassifyCompCategory;
template <class... _Ts, bool _False = false>
_LIBCPP_HIDE_FROM_ABI constexpr auto __get_comp_type() {
using _CCC = _ClassifyCompCategory;
constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
constexpr _CCC __cat = __comp_detail::__compute_comp_type(__type_kinds);
constexpr _CCC __cat = __comp_detail::__compute_comp_type(__type_kinds);
if constexpr (__cat == _None)
return void();
else if constexpr (__cat == _PartialOrd)
@ -80,12 +71,12 @@ constexpr auto __get_comp_type() {
} // namespace __comp_detail
// [cmp.common], common comparison category type
template<class... _Ts>
template <class... _Ts>
struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
};
template<class... _Ts>
template <class... _Ts>
using common_comparison_category_t = typename common_comparison_category<_Ts...>::type;
#endif // _LIBCPP_STD_VER >= 20

View file

@ -27,44 +27,46 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// [cmp.alg]
namespace __compare_partial_order_fallback {
struct __fn {
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
noexcept(noexcept(_VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
-> decltype( _VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
{ return _VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); }
struct __fn {
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept(
noexcept(std::partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))
-> decltype(std::partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))) {
return std::partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u));
}
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
noexcept(noexcept(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent :
_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less :
_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater :
partial_ordering::unordered))
-> decltype( _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent :
_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less :
_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater :
partial_ordering::unordered)
{
return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent :
_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less :
_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater :
partial_ordering::unordered;
}
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept(
std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent
: std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less
: std::forward<_Up>(__u) < std::forward<_Tp>(__t)
? partial_ordering::greater
: partial_ordering::unordered))
-> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent
: std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less
: std::forward<_Up>(__u) < std::forward<_Tp>(__t)
? partial_ordering::greater
: partial_ordering::unordered) {
return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent
: std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less
: std::forward<_Up>(__u) < std::forward<_Tp>(__t)
? partial_ordering::greater
: partial_ordering::unordered;
}
template<class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
-> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
{ return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
};
template <class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())))
-> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())) {
return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>());
}
};
} // namespace __compare_partial_order_fallback
inline namespace __cpo {
inline constexpr auto compare_partial_order_fallback = __compare_partial_order_fallback::__fn{};
inline constexpr auto compare_partial_order_fallback = __compare_partial_order_fallback::__fn{};
} // namespace __cpo
#endif // _LIBCPP_STD_VER >= 20

View file

@ -27,41 +27,43 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// [cmp.alg]
namespace __compare_strong_order_fallback {
struct __fn {
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
noexcept(noexcept(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
-> decltype( _VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
{ return _VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); }
struct __fn {
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept(
noexcept(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))
-> decltype(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))) {
return std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u));
}
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
noexcept(noexcept(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? strong_ordering::equal :
_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? strong_ordering::less :
strong_ordering::greater))
-> decltype( _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? strong_ordering::equal :
_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? strong_ordering::less :
strong_ordering::greater)
{
return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? strong_ordering::equal :
_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? strong_ordering::less :
strong_ordering::greater;
}
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept(
std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal
: std::forward<_Tp>(__t) < std::forward<_Up>(__u)
? strong_ordering::less
: strong_ordering::greater))
-> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal
: std::forward<_Tp>(__t) < std::forward<_Up>(__u)
? strong_ordering::less
: strong_ordering::greater) {
return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal
: std::forward<_Tp>(__t) < std::forward<_Up>(__u)
? strong_ordering::less
: strong_ordering::greater;
}
template<class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
-> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
{ return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
};
template <class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())))
-> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())) {
return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>());
}
};
} // namespace __compare_strong_order_fallback
inline namespace __cpo {
inline constexpr auto compare_strong_order_fallback = __compare_strong_order_fallback::__fn{};
inline constexpr auto compare_strong_order_fallback = __compare_strong_order_fallback::__fn{};
} // namespace __cpo
#endif // _LIBCPP_STD_VER >= 20

View file

@ -22,16 +22,15 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
struct _LIBCPP_TEMPLATE_VIS compare_three_way
{
template<class _T1, class _T2>
requires three_way_comparable_with<_T1, _T2>
constexpr _LIBCPP_HIDE_FROM_ABI
auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_VSTD::forward<_T1>(__t) <=> _VSTD::forward<_T2>(__u)))
{ return _VSTD::forward<_T1>(__t) <=> _VSTD::forward<_T2>(__u); }
struct _LIBCPP_TEMPLATE_VIS compare_three_way {
template <class _T1, class _T2>
requires three_way_comparable_with<_T1, _T2>
constexpr _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(std::forward<_T1>(__t) <=> std::forward<_T2>(__u))) {
return std::forward<_T1>(__t) <=> std::forward<_T2>(__u);
}
using is_transparent = void;
using is_transparent = void;
};
#endif // _LIBCPP_STD_VER >= 20

View file

@ -21,20 +21,21 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
template<class, class, class>
struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result { };
template <class, class, class>
struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result {};
template<class _Tp, class _Up>
struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<_Tp, _Up, decltype(
std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>(), void()
)> {
using type = decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>());
template <class _Tp, class _Up>
struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<
_Tp,
_Up,
decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>(), void())> {
using type = decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>());
};
template<class _Tp, class _Up = _Tp>
struct _LIBCPP_TEMPLATE_VIS compare_three_way_result : __compare_three_way_result<_Tp, _Up, void> { };
template <class _Tp, class _Up = _Tp>
struct _LIBCPP_TEMPLATE_VIS compare_three_way_result : __compare_three_way_result<_Tp, _Up, void> {};
template<class _Tp, class _Up = _Tp>
template <class _Tp, class _Up = _Tp>
using compare_three_way_result_t = typename compare_three_way_result<_Tp, _Up>::type;
#endif // _LIBCPP_STD_VER >= 20

View file

@ -27,41 +27,43 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// [cmp.alg]
namespace __compare_weak_order_fallback {
struct __fn {
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
noexcept(noexcept(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
-> decltype( _VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
{ return _VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); }
struct __fn {
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept(
noexcept(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))
-> decltype(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))) {
return std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u));
}
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
noexcept(noexcept(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
weak_ordering::greater))
-> decltype( _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
weak_ordering::greater)
{
return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
weak_ordering::greater;
}
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept(
std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent
: std::forward<_Tp>(__t) < std::forward<_Up>(__u)
? weak_ordering::less
: weak_ordering::greater))
-> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent
: std::forward<_Tp>(__t) < std::forward<_Up>(__u)
? weak_ordering::less
: weak_ordering::greater) {
return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent
: std::forward<_Tp>(__t) < std::forward<_Up>(__u)
? weak_ordering::less
: weak_ordering::greater;
}
template<class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
-> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
{ return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
};
template <class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())))
-> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())) {
return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>());
}
};
} // namespace __compare_weak_order_fallback
inline namespace __cpo {
inline constexpr auto compare_weak_order_fallback = __compare_weak_order_fallback::__fn{};
inline constexpr auto compare_weak_order_fallback = __compare_weak_order_fallback::__fn{};
} // namespace __cpo
#endif // _LIBCPP_STD_VER >= 20

View file

@ -22,46 +22,35 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
// exposition only
enum class _LIBCPP_ENUM_VIS _OrdResult : signed char {
__less = -1,
__equiv = 0,
__greater = 1
};
enum class _OrdResult : signed char { __less = -1, __equiv = 0, __greater = 1 };
enum class _LIBCPP_ENUM_VIS _NCmpResult : signed char {
__unordered = -127
};
enum class _NCmpResult : signed char { __unordered = -127 };
class partial_ordering;
class weak_ordering;
class strong_ordering;
template<class _Tp, class... _Args>
template <class _Tp, class... _Args>
inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
struct _CmpUnspecifiedParam {
_LIBCPP_HIDE_FROM_ABI constexpr
_CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
_LIBCPP_HIDE_FROM_ABI constexpr _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
template<class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
template <class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
_CmpUnspecifiedParam(_Tp) = delete;
};
class partial_ordering {
using _ValueT = signed char;
_LIBCPP_HIDE_FROM_ABI
explicit constexpr partial_ordering(_OrdResult __v) noexcept
: __value_(_ValueT(__v)) {}
_LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
_LIBCPP_HIDE_FROM_ABI
explicit constexpr partial_ordering(_NCmpResult __v) noexcept
: __value_(_ValueT(__v)) {}
_LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_NCmpResult __v) noexcept : __value_(_ValueT(__v)) {}
_LIBCPP_HIDE_FROM_ABI
constexpr bool __is_ordered() const noexcept {
_LIBCPP_HIDE_FROM_ABI constexpr bool __is_ordered() const noexcept {
return __value_ != _ValueT(_NCmpResult::__unordered);
}
public:
// valid values
static const partial_ordering less;
@ -70,63 +59,54 @@ public:
static const partial_ordering unordered;
// comparisons
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ == 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ < 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ <= 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ > 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ >= 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v.__is_ordered() && 0 < __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v.__is_ordered() && 0 <= __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v.__is_ordered() && 0 > __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v.__is_ordered() && 0 >= __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr partial_ordering
operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr partial_ordering
operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
}
private:
_ValueT __value_;
};
@ -139,76 +119,62 @@ inline constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__un
class weak_ordering {
using _ValueT = signed char;
_LIBCPP_HIDE_FROM_ABI
explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
_LIBCPP_HIDE_FROM_ABI explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
public:
static const weak_ordering less;
static const weak_ordering equivalent;
static const weak_ordering greater;
_LIBCPP_HIDE_FROM_ABI
constexpr operator partial_ordering() const noexcept {
_LIBCPP_HIDE_FROM_ABI constexpr operator partial_ordering() const noexcept {
return __value_ == 0 ? partial_ordering::equivalent
: (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
: (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
}
// comparisons
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ == 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ < 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ <= 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ > 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ >= 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 < __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 <= __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 > __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 >= __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
}
@ -223,8 +189,7 @@ inline constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater);
class strong_ordering {
using _ValueT = signed char;
_LIBCPP_HIDE_FROM_ABI
explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
_LIBCPP_HIDE_FROM_ABI explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
public:
static const strong_ordering less;
@ -233,74 +198,61 @@ public:
static const strong_ordering greater;
// conversions
_LIBCPP_HIDE_FROM_ABI
constexpr operator partial_ordering() const noexcept {
_LIBCPP_HIDE_FROM_ABI constexpr operator partial_ordering() const noexcept {
return __value_ == 0 ? partial_ordering::equivalent
: (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
: (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
}
_LIBCPP_HIDE_FROM_ABI
constexpr operator weak_ordering() const noexcept {
return __value_ == 0 ? weak_ordering::equivalent
: (__value_ < 0 ? weak_ordering::less : weak_ordering::greater);
_LIBCPP_HIDE_FROM_ABI constexpr operator weak_ordering() const noexcept {
return __value_ == 0 ? weak_ordering::equivalent : (__value_ < 0 ? weak_ordering::less : weak_ordering::greater);
}
// comparisons
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ == 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ < 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ <= 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ > 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ >= 0;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 < __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 <= __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 > __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 >= __v.__value_;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering
operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v;
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
_LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering
operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
}

View file

@ -28,43 +28,46 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// [cmp.alg]
namespace __partial_order {
struct __fn {
// NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, but only here
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<2>)
noexcept(noexcept(partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
-> decltype( partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
{ return partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
// NOLINTEND(libcpp-robust-against-adl)
void partial_order() = delete;
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
noexcept(noexcept(partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
-> decltype( partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
{ return partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
struct __fn {
// NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, but only here
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept(
noexcept(partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
-> decltype(partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
return partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
}
// NOLINTEND(libcpp-robust-against-adl)
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
noexcept(noexcept(partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
-> decltype( partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
{ return partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept(
noexcept(partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
-> decltype(partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
return partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
}
template<class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>())))
-> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()))
{ return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()); }
};
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(
noexcept(partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
-> decltype(partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
return partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
}
template <class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>())))
-> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>())) {
return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>());
}
};
} // namespace __partial_order
inline namespace __cpo {
inline constexpr auto partial_order = __partial_order::__fn{};
inline constexpr auto partial_order = __partial_order::__fn{};
} // namespace __cpo
#endif // _LIBCPP_STD_VER >= 20

View file

@ -13,11 +13,14 @@
#include <__compare/compare_three_way.h>
#include <__compare/ordering.h>
#include <__config>
#include <__math/exponential_functions.h>
#include <__math/traits.h>
#include <__type_traits/conditional.h>
#include <__type_traits/decay.h>
#include <__type_traits/is_floating_point.h>
#include <__type_traits/is_same.h>
#include <__utility/forward.h>
#include <__utility/priority_tag.h>
#include <cmath>
#include <cstdint>
#include <limits>
@ -34,100 +37,101 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// [cmp.alg]
namespace __strong_order {
struct __fn {
// NOLINTBEGIN(libcpp-robust-against-adl) strong_order should use ADL, but only here
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<2>)
noexcept(noexcept(strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
-> decltype( strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
{ return strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
// NOLINTEND(libcpp-robust-against-adl)
void strong_order() = delete;
template<class _Tp, class _Up, class _Dp = decay_t<_Tp>>
requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp>
_LIBCPP_HIDE_FROM_ABI static constexpr strong_ordering
__go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept
{
if constexpr (numeric_limits<_Dp>::is_iec559 && sizeof(_Dp) == sizeof(int32_t)) {
int32_t __rx = _VSTD::bit_cast<int32_t>(__t);
int32_t __ry = _VSTD::bit_cast<int32_t>(__u);
__rx = (__rx < 0) ? (numeric_limits<int32_t>::min() - __rx - 1) : __rx;
__ry = (__ry < 0) ? (numeric_limits<int32_t>::min() - __ry - 1) : __ry;
return (__rx <=> __ry);
} else if constexpr (numeric_limits<_Dp>::is_iec559 && sizeof(_Dp) == sizeof(int64_t)) {
int64_t __rx = _VSTD::bit_cast<int64_t>(__t);
int64_t __ry = _VSTD::bit_cast<int64_t>(__u);
__rx = (__rx < 0) ? (numeric_limits<int64_t>::min() - __rx - 1) : __rx;
__ry = (__ry < 0) ? (numeric_limits<int64_t>::min() - __ry - 1) : __ry;
return (__rx <=> __ry);
} else if (__t < __u) {
return strong_ordering::less;
} else if (__t > __u) {
return strong_ordering::greater;
} else if (__t == __u) {
if constexpr (numeric_limits<_Dp>::radix == 2) {
return _VSTD::signbit(__u) <=> _VSTD::signbit(__t);
} else {
// This is bullet 3 of the IEEE754 algorithm, relevant
// only for decimal floating-point;
// see https://stackoverflow.com/questions/69068075/
if (__t == 0 || _VSTD::isinf(__t)) {
return _VSTD::signbit(__u) <=> _VSTD::signbit(__t);
} else {
int __texp, __uexp;
(void)_VSTD::frexp(__t, &__texp);
(void)_VSTD::frexp(__u, &__uexp);
return (__t < 0) ? (__texp <=> __uexp) : (__uexp <=> __texp);
}
}
} else {
// They're unordered, so one of them must be a NAN.
// The order is -QNAN, -SNAN, numbers, +SNAN, +QNAN.
bool __t_is_nan = _VSTD::isnan(__t);
bool __u_is_nan = _VSTD::isnan(__u);
bool __t_is_negative = _VSTD::signbit(__t);
bool __u_is_negative = _VSTD::signbit(__u);
using _IntType = conditional_t<
sizeof(__t) == sizeof(int32_t), int32_t, conditional_t<
sizeof(__t) == sizeof(int64_t), int64_t, void>
>;
if constexpr (is_same_v<_IntType, void>) {
static_assert(sizeof(_Dp) == 0, "std::strong_order is unimplemented for this floating-point type");
} else if (__t_is_nan && __u_is_nan) {
// Order by sign bit, then by "payload bits" (we'll just use bit_cast).
if (__t_is_negative != __u_is_negative) {
return (__u_is_negative <=> __t_is_negative);
} else {
return _VSTD::bit_cast<_IntType>(__t) <=> _VSTD::bit_cast<_IntType>(__u);
}
} else if (__t_is_nan) {
return __t_is_negative ? strong_ordering::less : strong_ordering::greater;
} else {
return __u_is_negative ? strong_ordering::greater : strong_ordering::less;
}
}
struct __fn {
// NOLINTBEGIN(libcpp-robust-against-adl) strong_order should use ADL, but only here
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept(
noexcept(strong_ordering(strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
-> decltype(strong_ordering(strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
return strong_ordering(strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
}
// NOLINTEND(libcpp-robust-against-adl)
template <class _Tp, class _Up, class _Dp = decay_t<_Tp>>
requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp>
_LIBCPP_HIDE_FROM_ABI static constexpr strong_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept {
if constexpr (numeric_limits<_Dp>::is_iec559 && sizeof(_Dp) == sizeof(int32_t)) {
int32_t __rx = std::bit_cast<int32_t>(__t);
int32_t __ry = std::bit_cast<int32_t>(__u);
__rx = (__rx < 0) ? (numeric_limits<int32_t>::min() - __rx - 1) : __rx;
__ry = (__ry < 0) ? (numeric_limits<int32_t>::min() - __ry - 1) : __ry;
return (__rx <=> __ry);
} else if constexpr (numeric_limits<_Dp>::is_iec559 && sizeof(_Dp) == sizeof(int64_t)) {
int64_t __rx = std::bit_cast<int64_t>(__t);
int64_t __ry = std::bit_cast<int64_t>(__u);
__rx = (__rx < 0) ? (numeric_limits<int64_t>::min() - __rx - 1) : __rx;
__ry = (__ry < 0) ? (numeric_limits<int64_t>::min() - __ry - 1) : __ry;
return (__rx <=> __ry);
} else if (__t < __u) {
return strong_ordering::less;
} else if (__t > __u) {
return strong_ordering::greater;
} else if (__t == __u) {
if constexpr (numeric_limits<_Dp>::radix == 2) {
return __math::signbit(__u) <=> __math::signbit(__t);
} else {
// This is bullet 3 of the IEEE754 algorithm, relevant
// only for decimal floating-point;
// see https://stackoverflow.com/questions/69068075/
if (__t == 0 || __math::isinf(__t)) {
return __math::signbit(__u) <=> __math::signbit(__t);
} else {
int __texp, __uexp;
(void)__math::frexp(__t, &__texp);
(void)__math::frexp(__u, &__uexp);
return (__t < 0) ? (__texp <=> __uexp) : (__uexp <=> __texp);
}
}
} else {
// They're unordered, so one of them must be a NAN.
// The order is -QNAN, -SNAN, numbers, +SNAN, +QNAN.
bool __t_is_nan = __math::isnan(__t);
bool __u_is_nan = __math::isnan(__u);
bool __t_is_negative = __math::signbit(__t);
bool __u_is_negative = __math::signbit(__u);
using _IntType =
conditional_t< sizeof(__t) == sizeof(int32_t),
int32_t,
conditional_t< sizeof(__t) == sizeof(int64_t), int64_t, void> >;
if constexpr (is_same_v<_IntType, void>) {
static_assert(sizeof(_Dp) == 0, "std::strong_order is unimplemented for this floating-point type");
} else if (__t_is_nan && __u_is_nan) {
// Order by sign bit, then by "payload bits" (we'll just use bit_cast).
if (__t_is_negative != __u_is_negative) {
return (__u_is_negative <=> __t_is_negative);
} else {
return std::bit_cast<_IntType>(__t) <=> std::bit_cast<_IntType>(__u);
}
} else if (__t_is_nan) {
return __t_is_negative ? strong_ordering::less : strong_ordering::greater;
} else {
return __u_is_negative ? strong_ordering::greater : strong_ordering::less;
}
}
}
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
noexcept(noexcept(strong_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
-> decltype( strong_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
{ return strong_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(
noexcept(strong_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
-> decltype(strong_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
return strong_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
}
template<class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>())))
-> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()))
{ return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()); }
};
template <class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>())))
-> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>())) {
return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>());
}
};
} // namespace __strong_order
inline namespace __cpo {
inline constexpr auto strong_order = __strong_order::__fn{};
inline constexpr auto strong_order = __strong_order::__fn{};
} // namespace __cpo
#endif // _LIBCPP_STD_VER >= 20

View file

@ -25,12 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// [expos.only.func]
// TODO MODULES restore the lamba to match the Standard.
// See https://github.com/llvm/llvm-project/issues/57222
//_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
// []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
template <class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto __synth_three_way(const _Tp& __t, const _Up& __u)
_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way = []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
requires requires {
{ __t < __u } -> __boolean_testable;
{ __u < __t } -> __boolean_testable;
@ -45,7 +40,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __synth_three_way(const _Tp& __t, const _Up
return weak_ordering::greater;
return weak_ordering::equivalent;
}
}
};
template <class _Tp, class _Up = _Tp>
using __synth_three_way_result = decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>()));

View file

@ -27,30 +27,26 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
template<class _Tp, class _Cat>
concept __compares_as =
same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>;
template <class _Tp, class _Cat>
concept __compares_as = same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>;
template<class _Tp, class _Cat = partial_ordering>
template <class _Tp, class _Cat = partial_ordering>
concept three_way_comparable =
__weakly_equality_comparable_with<_Tp, _Tp> &&
__partially_ordered_with<_Tp, _Tp> &&
requires(__make_const_lvalue_ref<_Tp> __a, __make_const_lvalue_ref<_Tp> __b) {
{ __a <=> __b } -> __compares_as<_Cat>;
};
__weakly_equality_comparable_with<_Tp, _Tp> && __partially_ordered_with<_Tp, _Tp> &&
requires(__make_const_lvalue_ref<_Tp> __a, __make_const_lvalue_ref<_Tp> __b) {
{ __a <=> __b } -> __compares_as<_Cat>;
};
template<class _Tp, class _Up, class _Cat = partial_ordering>
template <class _Tp, class _Up, class _Cat = partial_ordering>
concept three_way_comparable_with =
three_way_comparable<_Tp, _Cat> &&
three_way_comparable<_Up, _Cat> &&
common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
three_way_comparable<common_reference_t<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>>, _Cat> &&
__weakly_equality_comparable_with<_Tp, _Up> &&
__partially_ordered_with<_Tp, _Up> &&
requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
{ __t <=> __u } -> __compares_as<_Cat>;
{ __u <=> __t } -> __compares_as<_Cat>;
};
three_way_comparable<_Tp, _Cat> && three_way_comparable<_Up, _Cat> &&
common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
three_way_comparable<common_reference_t<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>>, _Cat> &&
__weakly_equality_comparable_with<_Tp, _Up> && __partially_ordered_with<_Tp, _Up> &&
requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
{ __t <=> __u } -> __compares_as<_Cat>;
{ __u <=> __t } -> __compares_as<_Cat>;
};
#endif // _LIBCPP_STD_VER >= 20

View file

@ -13,10 +13,12 @@
#include <__compare/ordering.h>
#include <__compare/strong_order.h>
#include <__config>
#include <__math/traits.h>
#include <__type_traits/decay.h>
#include <__type_traits/is_floating_point.h>
#include <__type_traits/is_same.h>
#include <__utility/forward.h>
#include <__utility/priority_tag.h>
#include <cmath>
#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
# pragma GCC system_header
@ -28,71 +30,72 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// [cmp.alg]
namespace __weak_order {
struct __fn {
// NOLINTBEGIN(libcpp-robust-against-adl) weak_order should use ADL, but only here
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<3>)
noexcept(noexcept(weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
-> decltype( weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
{ return weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
// NOLINTEND(libcpp-robust-against-adl)
void weak_order() = delete;
template<class _Tp, class _Up, class _Dp = decay_t<_Tp>>
requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp>
_LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering
__go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept
{
partial_ordering __po = (__t <=> __u);
if (__po == partial_ordering::less) {
return weak_ordering::less;
} else if (__po == partial_ordering::equivalent) {
return weak_ordering::equivalent;
} else if (__po == partial_ordering::greater) {
return weak_ordering::greater;
} else {
// Otherwise, at least one of them is a NaN.
bool __t_is_nan = _VSTD::isnan(__t);
bool __u_is_nan = _VSTD::isnan(__u);
bool __t_is_negative = _VSTD::signbit(__t);
bool __u_is_negative = _VSTD::signbit(__u);
if (__t_is_nan && __u_is_nan) {
return (__u_is_negative <=> __t_is_negative);
} else if (__t_is_nan) {
return __t_is_negative ? weak_ordering::less : weak_ordering::greater;
} else {
return __u_is_negative ? weak_ordering::greater : weak_ordering::less;
}
}
}
struct __fn {
// NOLINTBEGIN(libcpp-robust-against-adl) weak_order should use ADL, but only here
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<3>) noexcept(
noexcept(weak_ordering(weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
-> decltype(weak_ordering(weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
return weak_ordering(weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
}
// NOLINTEND(libcpp-robust-against-adl)
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
noexcept(noexcept(weak_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
-> decltype( weak_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
{ return weak_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
template <class _Tp, class _Up, class _Dp = decay_t<_Tp>>
requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp>
_LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept {
partial_ordering __po = (__t <=> __u);
if (__po == partial_ordering::less) {
return weak_ordering::less;
} else if (__po == partial_ordering::equivalent) {
return weak_ordering::equivalent;
} else if (__po == partial_ordering::greater) {
return weak_ordering::greater;
} else {
// Otherwise, at least one of them is a NaN.
bool __t_is_nan = __math::isnan(__t);
bool __u_is_nan = __math::isnan(__u);
bool __t_is_negative = __math::signbit(__t);
bool __u_is_negative = __math::signbit(__u);
if (__t_is_nan && __u_is_nan) {
return (__u_is_negative <=> __t_is_negative);
} else if (__t_is_nan) {
return __t_is_negative ? weak_ordering::less : weak_ordering::greater;
} else {
return __u_is_negative ? weak_ordering::greater : weak_ordering::less;
}
}
}
template<class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto
__go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
noexcept(noexcept(weak_ordering(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
-> decltype( weak_ordering(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
{ return weak_ordering(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept(
noexcept(weak_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
-> decltype(weak_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
return weak_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
}
template<class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<3>())))
-> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<3>()))
{ return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<3>()); }
};
template <class _Tp, class _Up>
requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(
noexcept(weak_ordering(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))))
-> decltype(weak_ordering(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) {
return weak_ordering(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)));
}
template <class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<3>())))
-> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<3>())) {
return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<3>());
}
};
} // namespace __weak_order
inline namespace __cpo {
inline constexpr auto weak_order = __weak_order::__fn{};
inline constexpr auto weak_order = __weak_order::__fn{};
} // namespace __cpo
#endif // _LIBCPP_STD_VER >= 20