diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp index adc3d18de00..60c43e86e1b 100644 --- a/src/bench/prevector.cpp +++ b/src/bench/prevector.cpp @@ -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::value, +static_assert(!std::is_trivially_default_constructible_v, "expected nontrivial_t to not be trivially constructible"); typedef unsigned char trivial_t; -static_assert(std::is_trivially_default_constructible::value, +static_assert(std::is_trivially_default_constructible_v, "expected trivial_t to be trivially constructible"); template diff --git a/src/deploymentstatus.cpp b/src/deploymentstatus.cpp index 71f27024304..46fd70bc26a 100644 --- a/src/deploymentstatus.cpp +++ b/src/deploymentstatus.cpp @@ -24,7 +24,7 @@ static_assert(!ValidDeployment(static_cast(Consensu template static constexpr bool is_minimum() { - using U = typename std::underlying_type::type; + using U = std::underlying_type_t; return x == std::numeric_limits::min(); } diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index df1ced48a71..87f8c35a14c 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -45,7 +45,7 @@ enum class AddressPurpose; enum isminetype : unsigned int; struct CRecipient; struct WalletContext; -using isminefilter = std::underlying_type::type; +using isminefilter = std::underlying_type_t; } // namespace wallet namespace interfaces { diff --git a/src/logging/timer.h b/src/logging/timer.h index 0a6813cdd53..bc0d265e93a 100644 --- a/src/logging/timer.h +++ b/src/logging/timer.h @@ -67,11 +67,11 @@ public: } const auto duration{end_time - *m_start_t}; - if constexpr (std::is_same::value) { + if constexpr (std::is_same_v) { return strprintf("%s: %s (%iμs)", m_prefix, msg, Ticks(duration)); - } else if constexpr (std::is_same::value) { + } else if constexpr (std::is_same_v) { return strprintf("%s: %s (%.2fms)", m_prefix, msg, Ticks(duration)); - } else if constexpr (std::is_same::value) { + } else if constexpr (std::is_same_v) { return strprintf("%s: %s (%.2fs)", m_prefix, msg, Ticks(duration)); } else { static_assert(ALWAYS_FALSE, "Error: unexpected time type"); diff --git a/src/net_permissions.h b/src/net_permissions.h index 33babd62046..c93e18e160c 100644 --- a/src/net_permissions.h +++ b/src/net_permissions.h @@ -48,7 +48,7 @@ enum class NetPermissionFlags : uint32_t { }; static inline constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b) { - using t = typename std::underlying_type::type; + using t = std::underlying_type_t; return static_cast(static_cast(a) | static_cast(b)); } @@ -59,7 +59,7 @@ public: static std::vector ToStrings(NetPermissionFlags flags); static inline bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f) { - using t = typename std::underlying_type::type; + using t = std::underlying_type_t; return (static_cast(flags) & static_cast(f)) == static_cast(f); } static inline void AddFlag(NetPermissionFlags& flags, NetPermissionFlags f) @@ -74,7 +74,7 @@ public: static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f) { assert(f == NetPermissionFlags::Implicit); - using t = typename std::underlying_type::type; + using t = std::underlying_type_t; flags = static_cast(static_cast(flags) & ~static_cast(f)); } }; diff --git a/src/netbase.h b/src/netbase.h index bf4d7ececc6..d7c6e1c215c 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -37,12 +37,12 @@ enum class ConnectionDirection { Both = (In | Out), }; static inline ConnectionDirection& operator|=(ConnectionDirection& a, ConnectionDirection b) { - using underlying = typename std::underlying_type::type; + using underlying = std::underlying_type_t; a = ConnectionDirection(underlying(a) | underlying(b)); return a; } static inline bool operator&(ConnectionDirection a, ConnectionDirection b) { - using underlying = typename std::underlying_type::type; + using underlying = std::underlying_type_t; return (underlying(a) & underlying(b)); } diff --git a/src/random.h b/src/random.h index 203678b17c6..39bcd086f75 100644 --- a/src/random.h +++ b/src/random.h @@ -334,7 +334,7 @@ public: /** Generate a uniform random duration in the range [0..max). Precondition: max.count() > 0 */ template - Dur randrange(typename std::common_type_t range) noexcept + Dur randrange(std::common_type_t range) noexcept // Having the compiler infer the template argument from the function argument // is dangerous, because the desired return value generally has a different // type than the function argument. So std::common_type is used to force the diff --git a/src/randomenv.cpp b/src/randomenv.cpp index 7a46a5109bc..1811846677d 100644 --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -70,10 +70,10 @@ namespace { */ template CSHA512& operator<<(CSHA512& hasher, const T& data) { - static_assert(!std::is_same::type, char*>::value, "Calling operator<<(CSHA512, char*) is probably not what you want"); - static_assert(!std::is_same::type, unsigned char*>::value, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want"); - static_assert(!std::is_same::type, const char*>::value, "Calling operator<<(CSHA512, const char*) is probably not what you want"); - static_assert(!std::is_same::type, const unsigned char*>::value, "Calling operator<<(CSHA512, const unsigned char*) is probably not what you want"); + static_assert(!std::is_same_v, char*>, "Calling operator<<(CSHA512, char*) is probably not what you want"); + static_assert(!std::is_same_v, unsigned char*>, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want"); + static_assert(!std::is_same_v, const char*>, "Calling operator<<(CSHA512, const char*) is probably not what you want"); + static_assert(!std::is_same_v, const unsigned char*>, "Calling operator<<(CSHA512, const unsigned char*) is probably not what you want"); hasher.Write((const unsigned char*)&data, sizeof(data)); return hasher; } diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 2941dda8c0a..4c83517c8da 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -49,7 +49,7 @@ const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hu std::string GetAllOutputTypes() { std::vector ret; - using U = std::underlying_type::type; + using U = std::underlying_type_t; for (U i = (U)TxoutType::NONSTANDARD; i <= (U)TxoutType::WITNESS_UNKNOWN; ++i) { ret.emplace_back(GetTxnOutputType(static_cast(i))); } diff --git a/src/serialize.h b/src/serialize.h index 6384c95dba3..a1166b81a89 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -154,7 +154,7 @@ const Out& AsBase(const In& x) } #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) -#define SER_READ(obj, code) ser_action.SerRead(s, obj, [&](Stream& s, typename std::remove_const::type& obj) { code; }) +#define SER_READ(obj, code) ser_action.SerRead(s, obj, [&](Stream& s, std::remove_const_t& obj) { code; }) #define SER_WRITE(obj, code) ser_action.SerWrite(s, obj, [&](Stream& s, const Type& obj) { code; }) /** @@ -220,13 +220,13 @@ const Out& AsBase(const In& x) template \ void Serialize(Stream& s) const \ { \ - static_assert(std::is_same::value, "Serialize type mismatch"); \ + static_assert(std::is_same_v, "Serialize type mismatch"); \ Ser(s, *this); \ } \ template \ void Unserialize(Stream& s) \ { \ - static_assert(std::is_same::value, "Unserialize type mismatch"); \ + static_assert(std::is_same_v, "Unserialize type mismatch"); \ Unser(s, *this); \ } @@ -408,8 +408,8 @@ template struct CheckVarIntMode { constexpr CheckVarIntMode() { - static_assert(Mode != VarIntMode::DEFAULT || std::is_unsigned::value, "Unsigned type required with mode DEFAULT."); - static_assert(Mode != VarIntMode::NONNEGATIVE_SIGNED || std::is_signed::value, "Signed type required with mode NONNEGATIVE_SIGNED."); + static_assert(Mode != VarIntMode::DEFAULT || std::is_unsigned_v, "Unsigned type required with mode DEFAULT."); + static_assert(Mode != VarIntMode::NONNEGATIVE_SIGNED || std::is_signed_v, "Signed type required with mode NONNEGATIVE_SIGNED."); } }; @@ -474,7 +474,7 @@ I ReadVarInt(Stream& is) template class Wrapper { - static_assert(std::is_lvalue_reference::value, "Wrapper needs an lvalue reference type T"); + static_assert(std::is_lvalue_reference_v, "Wrapper needs an lvalue reference type T"); protected: T m_object; public: @@ -507,12 +507,12 @@ struct VarIntFormatter { template void Ser(Stream &s, I v) { - WriteVarInt::type>(s, v); + WriteVarInt>(s, v); } template void Unser(Stream& s, I& v) { - v = ReadVarInt::type>(s); + v = ReadVarInt>(s); } }; @@ -545,7 +545,7 @@ struct CustomUintFormatter template void Unser(Stream& s, I& v) { - using U = typename std::conditional::value, std::underlying_type, std::common_type>::type::type; + using U = typename std::conditional_t, std::underlying_type, std::common_type>::type; static_assert(std::numeric_limits::max() >= MAX && std::numeric_limits::min() <= 0, "Assigned type too small"); uint64_t raw = 0; if (BigEndian) { @@ -577,7 +577,7 @@ struct CompactSizeFormatter template void Ser(Stream& s, I v) { - static_assert(std::is_unsigned::value, "CompactSize only supported for unsigned integers"); + static_assert(std::is_unsigned_v, "CompactSize only supported for unsigned integers"); static_assert(std::numeric_limits::max() <= std::numeric_limits::max(), "CompactSize only supports 64-bit integers and below"); WriteCompactSize(s, v); diff --git a/src/sync.cpp b/src/sync.cpp index 93c91945414..e5be6fd1156 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -148,8 +148,8 @@ template static void push_lock(MutexType* c, const CLockLocation& locklocation) { constexpr bool is_recursive_mutex = - std::is_base_of::value || - std::is_base_of::value; + std::is_base_of_v || + std::is_base_of_v; LockData& lockdata = GetLockData(); std::lock_guard lock(lockdata.dd_mutex); diff --git a/src/test/fuzz/FuzzedDataProvider.h b/src/test/fuzz/FuzzedDataProvider.h index e57b95b6304..11f2fbdb8c8 100644 --- a/src/test/fuzz/FuzzedDataProvider.h +++ b/src/test/fuzz/FuzzedDataProvider.h @@ -203,7 +203,7 @@ template T FuzzedDataProvider::ConsumeIntegral() { // be less than or equal to |max|. template T FuzzedDataProvider::ConsumeIntegralInRange(T min, T max) { - static_assert(std::is_integral::value, "An integral type is required."); + static_assert(std::is_integral_v, "An integral type is required."); static_assert(sizeof(T) <= sizeof(uint64_t), "Unsupported integral type."); if (min > max) @@ -271,14 +271,14 @@ 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 T FuzzedDataProvider::ConsumeProbability() { - static_assert(std::is_floating_point::value, + static_assert(std::is_floating_point_v, "A floating point type is required."); // Use different integral types for different floating point types in order // to provide better density of the resulting values. using IntegralType = - typename std::conditional<(sizeof(T) <= sizeof(uint32_t)), uint32_t, - uint64_t>::type; + typename std::conditional_t<(sizeof(T) <= sizeof(uint32_t)), uint32_t, + uint64_t>; T result = static_cast(ConsumeIntegral()); result /= static_cast(std::numeric_limits::max()); @@ -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 T FuzzedDataProvider::ConsumeEnum() { - static_assert(std::is_enum::value, "|T| must be an enum type."); + static_assert(std::is_enum_v, "|T| must be an enum type."); return static_cast( ConsumeIntegralInRange(0, static_cast(T::kMaxValue))); } diff --git a/src/test/fuzz/integer.cpp b/src/test/fuzz/integer.cpp index b9e3154106f..a6729155d1f 100644 --- a/src/test/fuzz/integer.cpp +++ b/src/test/fuzz/integer.cpp @@ -63,7 +63,7 @@ FUZZ_TARGET(integer, .init = initialize_integer) const int16_t i16 = fuzzed_data_provider.ConsumeIntegral(); const uint8_t u8 = fuzzed_data_provider.ConsumeIntegral(); const int8_t i8 = fuzzed_data_provider.ConsumeIntegral(); - // We cannot assume a specific value of std::is_signed::value: + // We cannot assume a specific value of std::is_signed_v: // ConsumeIntegral() instead of casting from {u,}int8_t. const char ch = fuzzed_data_provider.ConsumeIntegral(); const bool b = fuzzed_data_provider.ConsumeBool(); diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index 38be59fb64b..28dd9805fed 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -134,7 +134,7 @@ template { return fuzzed_data_provider.ConsumeBool() ? fuzzed_data_provider.PickValueInArray(all_types) : - WeakEnumType(fuzzed_data_provider.ConsumeIntegral::type>()); + WeakEnumType(fuzzed_data_provider.ConsumeIntegral>()); } [[nodiscard]] inline opcodetype ConsumeOpcodeType(FuzzedDataProvider& fuzzed_data_provider) noexcept @@ -207,7 +207,7 @@ template template [[nodiscard]] bool MultiplicationOverflow(const T i, const T j) noexcept { - static_assert(std::is_integral::value, "Integral required."); + static_assert(std::is_integral_v, "Integral required."); if (std::numeric_limits::is_signed) { if (i > 0) { if (j > 0) { diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h index da121575554..19a500d191a 100644 --- a/src/univalue/include/univalue.h +++ b/src/univalue/include/univalue.h @@ -137,7 +137,7 @@ void UniValue::push_backV(It first, It last) template Int UniValue::getInt() const { - static_assert(std::is_integral::value); + static_assert(std::is_integral_v); checkType(VNUM); Int result; const auto [first_nonmatching, error_condition] = std::from_chars(val.data(), val.data() + val.size(), result); diff --git a/src/util/fs.h b/src/util/fs.h index f841e0d76c5..ce17682497c 100644 --- a/src/util/fs.h +++ b/src/util/fs.h @@ -163,7 +163,7 @@ static inline std::string PathToString(const path& path) #ifdef WIN32 return path.utf8string(); #else - static_assert(std::is_same::value, "PathToString not implemented on this platform"); + static_assert(std::is_same_v, "PathToString not implemented on this platform"); return path.std::filesystem::path::string(); #endif } diff --git a/src/util/overflow.h b/src/util/overflow.h index 67711af0a5e..ab20faf8557 100644 --- a/src/util/overflow.h +++ b/src/util/overflow.h @@ -14,7 +14,7 @@ template [[nodiscard]] bool AdditionOverflow(const T i, const T j) noexcept { - static_assert(std::is_integral::value, "Integral required."); + static_assert(std::is_integral_v, "Integral required."); if constexpr (std::numeric_limits::is_signed) { return (i > 0 && j > std::numeric_limits::max() - i) || (i < 0 && j < std::numeric_limits::min() - i); diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp index 15cb40aba13..eed8bf81370 100644 --- a/src/util/strencodings.cpp +++ b/src/util/strencodings.cpp @@ -204,7 +204,7 @@ namespace { template bool ParseIntegral(std::string_view str, T* out) { - static_assert(std::is_integral::value); + static_assert(std::is_integral_v); // Replicate the exact behavior of strtol/strtoll/strtoul/strtoull when // handling leading +/- for backwards compatibility. if (str.length() >= 2 && str[0] == '+' && str[1] == '-') { diff --git a/src/util/strencodings.h b/src/util/strencodings.h index d0809162faf..75030983d21 100644 --- a/src/util/strencodings.h +++ b/src/util/strencodings.h @@ -117,7 +117,7 @@ bool SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut) template T LocaleIndependentAtoi(std::string_view str) { - static_assert(std::is_integral::value); + static_assert(std::is_integral_v); 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 std::optional ToIntegral(std::string_view str) { - static_assert(std::is_integral::value); + static_assert(std::is_integral_v); 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{}) { diff --git a/src/util/vector.h b/src/util/vector.h index 1513562f1be..0c5645ebedf 100644 --- a/src/util/vector.h +++ b/src/util/vector.h @@ -20,9 +20,9 @@ * (list initialization always copies). */ template -inline std::vector::type> Vector(Args&&... args) +inline std::vector> Vector(Args&&... args) { - std::vector::type> ret; + std::vector> ret; ret.reserve(sizeof...(args)); // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html (void)std::initializer_list{(ret.emplace_back(std::forward(args)), 0)...}; diff --git a/src/wallet/types.h b/src/wallet/types.h index 7e3b2caeb19..66eac17d45b 100644 --- a/src/wallet/types.h +++ b/src/wallet/types.h @@ -48,7 +48,7 @@ enum isminetype : unsigned int { ISMINE_ENUM_ELEMENTS, }; /** used for bitflags of isminetype */ -using isminefilter = std::underlying_type::type; +using isminefilter = std::underlying_type_t; /** * Address purpose field that has been been stored with wallet sending and