mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-17 21:32:00 +01:00
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-
This commit is contained in:
parent
8327889f35
commit
ab2b67fce2
@ -16,11 +16,11 @@ struct nontrivial_t {
|
||||
nontrivial_t() = default;
|
||||
SERIALIZE_METHODS(nontrivial_t, obj) { READWRITE(obj.x); }
|
||||
};
|
||||
static_assert(!std::is_trivially_default_constructible<nontrivial_t>::value,
|
||||
static_assert(!std::is_trivially_default_constructible_v<nontrivial_t>,
|
||||
"expected nontrivial_t to not be trivially constructible");
|
||||
|
||||
typedef unsigned char trivial_t;
|
||||
static_assert(std::is_trivially_default_constructible<trivial_t>::value,
|
||||
static_assert(std::is_trivially_default_constructible_v<trivial_t>,
|
||||
"expected trivial_t to be trivially constructible");
|
||||
|
||||
template <typename T>
|
||||
|
@ -67,11 +67,11 @@ public:
|
||||
}
|
||||
const auto duration{end_time - *m_start_t};
|
||||
|
||||
if constexpr (std::is_same<TimeType, std::chrono::microseconds>::value) {
|
||||
if constexpr (std::is_same_v<TimeType, std::chrono::microseconds>) {
|
||||
return strprintf("%s: %s (%iμs)", m_prefix, msg, Ticks<std::chrono::microseconds>(duration));
|
||||
} else if constexpr (std::is_same<TimeType, std::chrono::milliseconds>::value) {
|
||||
} else if constexpr (std::is_same_v<TimeType, std::chrono::milliseconds>) {
|
||||
return strprintf("%s: %s (%.2fms)", m_prefix, msg, Ticks<MillisecondsDouble>(duration));
|
||||
} else if constexpr (std::is_same<TimeType, std::chrono::seconds>::value) {
|
||||
} else if constexpr (std::is_same_v<TimeType, std::chrono::seconds>) {
|
||||
return strprintf("%s: %s (%.2fs)", m_prefix, msg, Ticks<SecondsDouble>(duration));
|
||||
} else {
|
||||
static_assert(ALWAYS_FALSE<TimeType>, "Error: unexpected time type");
|
||||
|
@ -220,13 +220,13 @@ const Out& AsBase(const In& x)
|
||||
template <typename Stream> \
|
||||
void Serialize(Stream& s) const \
|
||||
{ \
|
||||
static_assert(std::is_same<const cls&, decltype(*this)>::value, "Serialize type mismatch"); \
|
||||
static_assert(std::is_same_v<const cls&, decltype(*this)>, "Serialize type mismatch"); \
|
||||
Ser(s, *this); \
|
||||
} \
|
||||
template <typename Stream> \
|
||||
void Unserialize(Stream& s) \
|
||||
{ \
|
||||
static_assert(std::is_same<cls&, decltype(*this)>::value, "Unserialize type mismatch"); \
|
||||
static_assert(std::is_same_v<cls&, decltype(*this)>, "Unserialize type mismatch"); \
|
||||
Unser(s, *this); \
|
||||
}
|
||||
|
||||
@ -408,8 +408,8 @@ template <VarIntMode Mode, typename I>
|
||||
struct CheckVarIntMode {
|
||||
constexpr CheckVarIntMode()
|
||||
{
|
||||
static_assert(Mode != VarIntMode::DEFAULT || std::is_unsigned<I>::value, "Unsigned type required with mode DEFAULT.");
|
||||
static_assert(Mode != VarIntMode::NONNEGATIVE_SIGNED || std::is_signed<I>::value, "Signed type required with mode NONNEGATIVE_SIGNED.");
|
||||
static_assert(Mode != VarIntMode::DEFAULT || std::is_unsigned_v<I>, "Unsigned type required with mode DEFAULT.");
|
||||
static_assert(Mode != VarIntMode::NONNEGATIVE_SIGNED || std::is_signed_v<I>, "Signed type required with mode NONNEGATIVE_SIGNED.");
|
||||
}
|
||||
};
|
||||
|
||||
@ -474,7 +474,7 @@ I ReadVarInt(Stream& is)
|
||||
template<typename Formatter, typename T>
|
||||
class Wrapper
|
||||
{
|
||||
static_assert(std::is_lvalue_reference<T>::value, "Wrapper needs an lvalue reference type T");
|
||||
static_assert(std::is_lvalue_reference_v<T>, "Wrapper needs an lvalue reference type T");
|
||||
protected:
|
||||
T m_object;
|
||||
public:
|
||||
@ -545,7 +545,7 @@ struct CustomUintFormatter
|
||||
|
||||
template <typename Stream, typename I> void Unser(Stream& s, I& v)
|
||||
{
|
||||
using U = typename std::conditional<std::is_enum<I>::value, std::underlying_type<I>, std::common_type<I>>::type::type;
|
||||
using U = typename std::conditional<std::is_enum_v<I>, std::underlying_type<I>, std::common_type<I>>::type::type;
|
||||
static_assert(std::numeric_limits<U>::max() >= MAX && std::numeric_limits<U>::min() <= 0, "Assigned type too small");
|
||||
uint64_t raw = 0;
|
||||
if (BigEndian) {
|
||||
@ -577,7 +577,7 @@ struct CompactSizeFormatter
|
||||
template<typename Stream, typename I>
|
||||
void Ser(Stream& s, I v)
|
||||
{
|
||||
static_assert(std::is_unsigned<I>::value, "CompactSize only supported for unsigned integers");
|
||||
static_assert(std::is_unsigned_v<I>, "CompactSize only supported for unsigned integers");
|
||||
static_assert(std::numeric_limits<I>::max() <= std::numeric_limits<uint64_t>::max(), "CompactSize only supports 64-bit integers and below");
|
||||
|
||||
WriteCompactSize<Stream>(s, v);
|
||||
|
@ -148,8 +148,8 @@ template <typename MutexType>
|
||||
static void push_lock(MutexType* c, const CLockLocation& locklocation)
|
||||
{
|
||||
constexpr bool is_recursive_mutex =
|
||||
std::is_base_of<RecursiveMutex, MutexType>::value ||
|
||||
std::is_base_of<std::recursive_mutex, MutexType>::value;
|
||||
std::is_base_of_v<RecursiveMutex, MutexType> ||
|
||||
std::is_base_of_v<std::recursive_mutex, MutexType>;
|
||||
|
||||
LockData& lockdata = GetLockData();
|
||||
std::lock_guard<std::mutex> lock(lockdata.dd_mutex);
|
||||
|
@ -203,7 +203,7 @@ template <typename T> T FuzzedDataProvider::ConsumeIntegral() {
|
||||
// be less than or equal to |max|.
|
||||
template <typename T>
|
||||
T FuzzedDataProvider::ConsumeIntegralInRange(T min, T max) {
|
||||
static_assert(std::is_integral<T>::value, "An integral type is required.");
|
||||
static_assert(std::is_integral_v<T>, "An integral type is required.");
|
||||
static_assert(sizeof(T) <= sizeof(uint64_t), "Unsupported integral type.");
|
||||
|
||||
if (min > max)
|
||||
@ -271,7 +271,7 @@ T FuzzedDataProvider::ConsumeFloatingPointInRange(T min, T max) {
|
||||
// Returns a floating point number in the range [0.0, 1.0]. If there's no
|
||||
// input data left, always returns 0.
|
||||
template <typename T> T FuzzedDataProvider::ConsumeProbability() {
|
||||
static_assert(std::is_floating_point<T>::value,
|
||||
static_assert(std::is_floating_point_v<T>,
|
||||
"A floating point type is required.");
|
||||
|
||||
// Use different integral types for different floating point types in order
|
||||
@ -294,7 +294,7 @@ inline bool FuzzedDataProvider::ConsumeBool() {
|
||||
// also contain |kMaxValue| aliased to its largest (inclusive) value. Such as:
|
||||
// enum class Foo { SomeValue, OtherValue, kMaxValue = OtherValue };
|
||||
template <typename T> T FuzzedDataProvider::ConsumeEnum() {
|
||||
static_assert(std::is_enum<T>::value, "|T| must be an enum type.");
|
||||
static_assert(std::is_enum_v<T>, "|T| must be an enum type.");
|
||||
return static_cast<T>(
|
||||
ConsumeIntegralInRange<uint32_t>(0, static_cast<uint32_t>(T::kMaxValue)));
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ FUZZ_TARGET(integer, .init = initialize_integer)
|
||||
const int16_t i16 = fuzzed_data_provider.ConsumeIntegral<int16_t>();
|
||||
const uint8_t u8 = fuzzed_data_provider.ConsumeIntegral<uint8_t>();
|
||||
const int8_t i8 = fuzzed_data_provider.ConsumeIntegral<int8_t>();
|
||||
// We cannot assume a specific value of std::is_signed<char>::value:
|
||||
// We cannot assume a specific value of std::is_signed_v<char>:
|
||||
// ConsumeIntegral<char>() instead of casting from {u,}int8_t.
|
||||
const char ch = fuzzed_data_provider.ConsumeIntegral<char>();
|
||||
const bool b = fuzzed_data_provider.ConsumeBool();
|
||||
|
@ -207,7 +207,7 @@ template <typename WeakEnumType, size_t size>
|
||||
template <typename T>
|
||||
[[nodiscard]] bool MultiplicationOverflow(const T i, const T j) noexcept
|
||||
{
|
||||
static_assert(std::is_integral<T>::value, "Integral required.");
|
||||
static_assert(std::is_integral_v<T>, "Integral required.");
|
||||
if (std::numeric_limits<T>::is_signed) {
|
||||
if (i > 0) {
|
||||
if (j > 0) {
|
||||
|
@ -137,7 +137,7 @@ void UniValue::push_backV(It first, It last)
|
||||
template <typename Int>
|
||||
Int UniValue::getInt() const
|
||||
{
|
||||
static_assert(std::is_integral<Int>::value);
|
||||
static_assert(std::is_integral_v<Int>);
|
||||
checkType(VNUM);
|
||||
Int result;
|
||||
const auto [first_nonmatching, error_condition] = std::from_chars(val.data(), val.data() + val.size(), result);
|
||||
|
@ -163,7 +163,7 @@ static inline std::string PathToString(const path& path)
|
||||
#ifdef WIN32
|
||||
return path.utf8string();
|
||||
#else
|
||||
static_assert(std::is_same<path::string_type, std::string>::value, "PathToString not implemented on this platform");
|
||||
static_assert(std::is_same_v<path::string_type, std::string>, "PathToString not implemented on this platform");
|
||||
return path.std::filesystem::path::string();
|
||||
#endif
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
template <class T>
|
||||
[[nodiscard]] bool AdditionOverflow(const T i, const T j) noexcept
|
||||
{
|
||||
static_assert(std::is_integral<T>::value, "Integral required.");
|
||||
static_assert(std::is_integral_v<T>, "Integral required.");
|
||||
if constexpr (std::numeric_limits<T>::is_signed) {
|
||||
return (i > 0 && j > std::numeric_limits<T>::max() - i) ||
|
||||
(i < 0 && j < std::numeric_limits<T>::min() - i);
|
||||
|
@ -204,7 +204,7 @@ namespace {
|
||||
template <typename T>
|
||||
bool ParseIntegral(std::string_view str, T* out)
|
||||
{
|
||||
static_assert(std::is_integral<T>::value);
|
||||
static_assert(std::is_integral_v<T>);
|
||||
// Replicate the exact behavior of strtol/strtoll/strtoul/strtoull when
|
||||
// handling leading +/- for backwards compatibility.
|
||||
if (str.length() >= 2 && str[0] == '+' && str[1] == '-') {
|
||||
|
@ -117,7 +117,7 @@ bool SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut)
|
||||
template <typename T>
|
||||
T LocaleIndependentAtoi(std::string_view str)
|
||||
{
|
||||
static_assert(std::is_integral<T>::value);
|
||||
static_assert(std::is_integral_v<T>);
|
||||
T result;
|
||||
// Emulate atoi(...) handling of white space and leading +/-.
|
||||
std::string_view s = util::TrimStringView(str);
|
||||
@ -178,7 +178,7 @@ constexpr inline bool IsSpace(char c) noexcept {
|
||||
template <typename T>
|
||||
std::optional<T> ToIntegral(std::string_view str)
|
||||
{
|
||||
static_assert(std::is_integral<T>::value);
|
||||
static_assert(std::is_integral_v<T>);
|
||||
T result;
|
||||
const auto [first_nonmatching, error_condition] = std::from_chars(str.data(), str.data() + str.size(), result);
|
||||
if (first_nonmatching != str.data() + str.size() || error_condition != std::errc{}) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user