From c9192ecde7c1ec35e6c3d33cd221dd0e4b8d5360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=98=D0=B7?= =?UTF-8?q?=D0=B2=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Mon, 16 Sep 2024 22:43:55 +0300 Subject: [PATCH] constexpr-fn-switch --- libcxx/include/__algorithm/stable_sort.h | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libcxx/include/__algorithm/stable_sort.h b/libcxx/include/__algorithm/stable_sort.h index f6fcd9f1a635416..0879fa086f1b691 100644 --- a/libcxx/include/__algorithm/stable_sort.h +++ b/libcxx/include/__algorithm/stable_sort.h @@ -194,25 +194,25 @@ struct __stable_sort_switch { static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value; }; -template -struct __radix_sort_min_switch { - static const unsigned value = (1 << 10); -}; +template +constexpr unsigned __radix_sort_min_bound() { + static_assert(is_integral<_Tp>::value); + if constexpr (sizeof(_Tp) == 1) { + return 1 << 8; + } -template -struct __radix_sort_min_switch<_Int8, __enable_if_t::value && sizeof(_Int8) == 1> > { - static const unsigned value = (1 << 8); -}; + return 1 << 10; +} -template -struct __radix_sort_max_switch { - static const unsigned value = (1 << 16); -}; +template +constexpr unsigned __radix_sort_max_bound() { + static_assert(is_integral<_Tp>::value); + if constexpr (sizeof(_Tp) == 8) { + return 1 << 15; + } -template -struct __radix_sort_max_switch<_Int64, __enable_if_t::value && sizeof(_Int64) == 8> > { - static const unsigned value = (1 << 15); -}; + return 1 << 16; +} template void __stable_sort(_RandomAccessIterator __first, @@ -241,8 +241,8 @@ void __stable_sort(_RandomAccessIterator __first, constexpr auto __integral_value = is_integral_v; constexpr auto __allowed_radix_sort = __default_comp && __integral_value; if constexpr (__allowed_radix_sort) { - if (__len <= __buff_size && __len >= static_cast(__radix_sort_min_switch::value) && - __len <= static_cast(__radix_sort_max_switch::value)) { + if (__len <= __buff_size && __len >= static_cast(__radix_sort_min_bound()) && + __len <= static_cast(__radix_sort_max_bound())) { std::__radix_sort(__first, __last, __buff); return; }