Skip to content

Commit 773d357

Browse files
authored
[libc++] Simplify the implementation of __next_prime a bit (#143512)
1 parent 8d7da9a commit 773d357

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

libcxx/src/hash.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <__hash_table>
1010
#include <algorithm>
1111
#include <stdexcept>
12-
#include <type_traits>
1312

1413
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wtautological-constant-out-of-range-compare")
1514

@@ -52,16 +51,15 @@ const unsigned indices[] = {
5251
// are fewer potential primes to search, and fewer potential primes to divide
5352
// against.
5453

55-
template <size_t _Sz = sizeof(size_t)>
56-
inline _LIBCPP_HIDE_FROM_ABI typename enable_if<_Sz == 4, void>::type __check_for_overflow(size_t N) {
57-
if (N > 0xFFFFFFFB)
58-
std::__throw_overflow_error("__next_prime overflow");
59-
}
60-
61-
template <size_t _Sz = sizeof(size_t)>
62-
inline _LIBCPP_HIDE_FROM_ABI typename enable_if<_Sz == 8, void>::type __check_for_overflow(size_t N) {
63-
if (N > 0xFFFFFFFFFFFFFFC5ull)
64-
std::__throw_overflow_error("__next_prime overflow");
54+
inline void __check_for_overflow(size_t N) {
55+
if constexpr (sizeof(size_t) == 4) {
56+
if (N > 0xFFFFFFFB)
57+
std::__throw_overflow_error("__next_prime overflow");
58+
} else {
59+
static_assert(sizeof(size_t) == 8);
60+
if (N > 0xFFFFFFFFFFFFFFC5ull)
61+
std::__throw_overflow_error("__next_prime overflow");
62+
}
6563
}
6664

6765
size_t __next_prime(size_t n) {

0 commit comments

Comments
 (0)