Skip to content

Commit ab2b67f

Browse files
committed
scripted-diff: modernize outdated trait patterns - values
See https://en.cppreference.com/w/cpp/types/is_enum for more details. -BEGIN VERIFY SCRIPT- sed -i -E 's/(std::[a-z_]+)(<[^<>]+>)::value\b/\1_v\2/g' $(git grep -l '::value' ./src ':(exclude)src/bench/nanobench.h' ':(exclude)src/minisketch' ':(exclude)src/span.h') -END VERIFY SCRIPT-
1 parent 8327889 commit ab2b67f

File tree

12 files changed

+25
-25
lines changed

12 files changed

+25
-25
lines changed

src/bench/prevector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ struct nontrivial_t {
1616
nontrivial_t() = default;
1717
SERIALIZE_METHODS(nontrivial_t, obj) { READWRITE(obj.x); }
1818
};
19-
static_assert(!std::is_trivially_default_constructible<nontrivial_t>::value,
19+
static_assert(!std::is_trivially_default_constructible_v<nontrivial_t>,
2020
"expected nontrivial_t to not be trivially constructible");
2121

2222
typedef unsigned char trivial_t;
23-
static_assert(std::is_trivially_default_constructible<trivial_t>::value,
23+
static_assert(std::is_trivially_default_constructible_v<trivial_t>,
2424
"expected trivial_t to be trivially constructible");
2525

2626
template <typename T>

src/logging/timer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ class Timer
6767
}
6868
const auto duration{end_time - *m_start_t};
6969

70-
if constexpr (std::is_same<TimeType, std::chrono::microseconds>::value) {
70+
if constexpr (std::is_same_v<TimeType, std::chrono::microseconds>) {
7171
return strprintf("%s: %s (%iμs)", m_prefix, msg, Ticks<std::chrono::microseconds>(duration));
72-
} else if constexpr (std::is_same<TimeType, std::chrono::milliseconds>::value) {
72+
} else if constexpr (std::is_same_v<TimeType, std::chrono::milliseconds>) {
7373
return strprintf("%s: %s (%.2fms)", m_prefix, msg, Ticks<MillisecondsDouble>(duration));
74-
} else if constexpr (std::is_same<TimeType, std::chrono::seconds>::value) {
74+
} else if constexpr (std::is_same_v<TimeType, std::chrono::seconds>) {
7575
return strprintf("%s: %s (%.2fs)", m_prefix, msg, Ticks<SecondsDouble>(duration));
7676
} else {
7777
static_assert(ALWAYS_FALSE<TimeType>, "Error: unexpected time type");

src/serialize.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ const Out& AsBase(const In& x)
220220
template <typename Stream> \
221221
void Serialize(Stream& s) const \
222222
{ \
223-
static_assert(std::is_same<const cls&, decltype(*this)>::value, "Serialize type mismatch"); \
223+
static_assert(std::is_same_v<const cls&, decltype(*this)>, "Serialize type mismatch"); \
224224
Ser(s, *this); \
225225
} \
226226
template <typename Stream> \
227227
void Unserialize(Stream& s) \
228228
{ \
229-
static_assert(std::is_same<cls&, decltype(*this)>::value, "Unserialize type mismatch"); \
229+
static_assert(std::is_same_v<cls&, decltype(*this)>, "Unserialize type mismatch"); \
230230
Unser(s, *this); \
231231
}
232232

@@ -408,8 +408,8 @@ template <VarIntMode Mode, typename I>
408408
struct CheckVarIntMode {
409409
constexpr CheckVarIntMode()
410410
{
411-
static_assert(Mode != VarIntMode::DEFAULT || std::is_unsigned<I>::value, "Unsigned type required with mode DEFAULT.");
412-
static_assert(Mode != VarIntMode::NONNEGATIVE_SIGNED || std::is_signed<I>::value, "Signed type required with mode NONNEGATIVE_SIGNED.");
411+
static_assert(Mode != VarIntMode::DEFAULT || std::is_unsigned_v<I>, "Unsigned type required with mode DEFAULT.");
412+
static_assert(Mode != VarIntMode::NONNEGATIVE_SIGNED || std::is_signed_v<I>, "Signed type required with mode NONNEGATIVE_SIGNED.");
413413
}
414414
};
415415

@@ -474,7 +474,7 @@ I ReadVarInt(Stream& is)
474474
template<typename Formatter, typename T>
475475
class Wrapper
476476
{
477-
static_assert(std::is_lvalue_reference<T>::value, "Wrapper needs an lvalue reference type T");
477+
static_assert(std::is_lvalue_reference_v<T>, "Wrapper needs an lvalue reference type T");
478478
protected:
479479
T m_object;
480480
public:
@@ -545,7 +545,7 @@ struct CustomUintFormatter
545545

546546
template <typename Stream, typename I> void Unser(Stream& s, I& v)
547547
{
548-
using U = typename std::conditional<std::is_enum<I>::value, std::underlying_type<I>, std::common_type<I>>::type::type;
548+
using U = typename std::conditional<std::is_enum_v<I>, std::underlying_type<I>, std::common_type<I>>::type::type;
549549
static_assert(std::numeric_limits<U>::max() >= MAX && std::numeric_limits<U>::min() <= 0, "Assigned type too small");
550550
uint64_t raw = 0;
551551
if (BigEndian) {
@@ -577,7 +577,7 @@ struct CompactSizeFormatter
577577
template<typename Stream, typename I>
578578
void Ser(Stream& s, I v)
579579
{
580-
static_assert(std::is_unsigned<I>::value, "CompactSize only supported for unsigned integers");
580+
static_assert(std::is_unsigned_v<I>, "CompactSize only supported for unsigned integers");
581581
static_assert(std::numeric_limits<I>::max() <= std::numeric_limits<uint64_t>::max(), "CompactSize only supports 64-bit integers and below");
582582

583583
WriteCompactSize<Stream>(s, v);

src/sync.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ template <typename MutexType>
148148
static void push_lock(MutexType* c, const CLockLocation& locklocation)
149149
{
150150
constexpr bool is_recursive_mutex =
151-
std::is_base_of<RecursiveMutex, MutexType>::value ||
152-
std::is_base_of<std::recursive_mutex, MutexType>::value;
151+
std::is_base_of_v<RecursiveMutex, MutexType> ||
152+
std::is_base_of_v<std::recursive_mutex, MutexType>;
153153

154154
LockData& lockdata = GetLockData();
155155
std::lock_guard<std::mutex> lock(lockdata.dd_mutex);

src/test/fuzz/FuzzedDataProvider.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ template <typename T> T FuzzedDataProvider::ConsumeIntegral() {
203203
// be less than or equal to |max|.
204204
template <typename T>
205205
T FuzzedDataProvider::ConsumeIntegralInRange(T min, T max) {
206-
static_assert(std::is_integral<T>::value, "An integral type is required.");
206+
static_assert(std::is_integral_v<T>, "An integral type is required.");
207207
static_assert(sizeof(T) <= sizeof(uint64_t), "Unsupported integral type.");
208208

209209
if (min > max)
@@ -271,7 +271,7 @@ T FuzzedDataProvider::ConsumeFloatingPointInRange(T min, T max) {
271271
// Returns a floating point number in the range [0.0, 1.0]. If there's no
272272
// input data left, always returns 0.
273273
template <typename T> T FuzzedDataProvider::ConsumeProbability() {
274-
static_assert(std::is_floating_point<T>::value,
274+
static_assert(std::is_floating_point_v<T>,
275275
"A floating point type is required.");
276276

277277
// Use different integral types for different floating point types in order
@@ -294,7 +294,7 @@ inline bool FuzzedDataProvider::ConsumeBool() {
294294
// also contain |kMaxValue| aliased to its largest (inclusive) value. Such as:
295295
// enum class Foo { SomeValue, OtherValue, kMaxValue = OtherValue };
296296
template <typename T> T FuzzedDataProvider::ConsumeEnum() {
297-
static_assert(std::is_enum<T>::value, "|T| must be an enum type.");
297+
static_assert(std::is_enum_v<T>, "|T| must be an enum type.");
298298
return static_cast<T>(
299299
ConsumeIntegralInRange<uint32_t>(0, static_cast<uint32_t>(T::kMaxValue)));
300300
}

src/test/fuzz/integer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ FUZZ_TARGET(integer, .init = initialize_integer)
6363
const int16_t i16 = fuzzed_data_provider.ConsumeIntegral<int16_t>();
6464
const uint8_t u8 = fuzzed_data_provider.ConsumeIntegral<uint8_t>();
6565
const int8_t i8 = fuzzed_data_provider.ConsumeIntegral<int8_t>();
66-
// We cannot assume a specific value of std::is_signed<char>::value:
66+
// We cannot assume a specific value of std::is_signed_v<char>:
6767
// ConsumeIntegral<char>() instead of casting from {u,}int8_t.
6868
const char ch = fuzzed_data_provider.ConsumeIntegral<char>();
6969
const bool b = fuzzed_data_provider.ConsumeBool();

src/test/fuzz/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ template <typename WeakEnumType, size_t size>
207207
template <typename T>
208208
[[nodiscard]] bool MultiplicationOverflow(const T i, const T j) noexcept
209209
{
210-
static_assert(std::is_integral<T>::value, "Integral required.");
210+
static_assert(std::is_integral_v<T>, "Integral required.");
211211
if (std::numeric_limits<T>::is_signed) {
212212
if (i > 0) {
213213
if (j > 0) {

src/univalue/include/univalue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void UniValue::push_backV(It first, It last)
137137
template <typename Int>
138138
Int UniValue::getInt() const
139139
{
140-
static_assert(std::is_integral<Int>::value);
140+
static_assert(std::is_integral_v<Int>);
141141
checkType(VNUM);
142142
Int result;
143143
const auto [first_nonmatching, error_condition] = std::from_chars(val.data(), val.data() + val.size(), result);

src/util/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static inline std::string PathToString(const path& path)
163163
#ifdef WIN32
164164
return path.utf8string();
165165
#else
166-
static_assert(std::is_same<path::string_type, std::string>::value, "PathToString not implemented on this platform");
166+
static_assert(std::is_same_v<path::string_type, std::string>, "PathToString not implemented on this platform");
167167
return path.std::filesystem::path::string();
168168
#endif
169169
}

src/util/overflow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
template <class T>
1515
[[nodiscard]] bool AdditionOverflow(const T i, const T j) noexcept
1616
{
17-
static_assert(std::is_integral<T>::value, "Integral required.");
17+
static_assert(std::is_integral_v<T>, "Integral required.");
1818
if constexpr (std::numeric_limits<T>::is_signed) {
1919
return (i > 0 && j > std::numeric_limits<T>::max() - i) ||
2020
(i < 0 && j < std::numeric_limits<T>::min() - i);

0 commit comments

Comments
 (0)