Skip to content

Commit

Permalink
constexpr-fn-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
izvolov committed Sep 16, 2024
1 parent 3f0ffd4 commit c9192ec
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions libcxx/include/__algorithm/stable_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,25 @@ struct __stable_sort_switch {
static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value;
};

template <class _Tp, class = void>
struct __radix_sort_min_switch {
static const unsigned value = (1 << 10);
};
template <class _Tp>
constexpr unsigned __radix_sort_min_bound() {
static_assert(is_integral<_Tp>::value);
if constexpr (sizeof(_Tp) == 1) {
return 1 << 8;
}

template <class _Int8>
struct __radix_sort_min_switch<_Int8, __enable_if_t<is_integral<_Int8>::value && sizeof(_Int8) == 1> > {
static const unsigned value = (1 << 8);
};
return 1 << 10;
}

template <class _Tp, class = void>
struct __radix_sort_max_switch {
static const unsigned value = (1 << 16);
};
template <class _Tp>
constexpr unsigned __radix_sort_max_bound() {
static_assert(is_integral<_Tp>::value);
if constexpr (sizeof(_Tp) == 8) {
return 1 << 15;
}

template <class _Int64>
struct __radix_sort_max_switch<_Int64, __enable_if_t<is_integral<_Int64>::value && sizeof(_Int64) == 8> > {
static const unsigned value = (1 << 15);
};
return 1 << 16;
}

template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
void __stable_sort(_RandomAccessIterator __first,
Expand Down Expand Up @@ -241,8 +241,8 @@ void __stable_sort(_RandomAccessIterator __first,
constexpr auto __integral_value = is_integral_v<value_type >;
constexpr auto __allowed_radix_sort = __default_comp && __integral_value;
if constexpr (__allowed_radix_sort) {
if (__len <= __buff_size && __len >= static_cast<difference_type>(__radix_sort_min_switch<value_type>::value) &&
__len <= static_cast<difference_type>(__radix_sort_max_switch<value_type>::value)) {
if (__len <= __buff_size && __len >= static_cast<difference_type>(__radix_sort_min_bound<value_type>()) &&
__len <= static_cast<difference_type>(__radix_sort_max_bound<value_type>())) {
std::__radix_sort(__first, __last, __buff);
return;
}
Expand Down

0 comments on commit c9192ec

Please sign in to comment.