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; }