mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-17 21:32:00 +01:00
scripted-diff: modernize outdated trait patterns - types
The use of e.g. `std::underlying_type_t<T>` replaces the older `typename std::underlying_type<T>::type`. The `_t` helper alias template (such as `std::underlying_type_t<T>`) introduced in C++14 offers a cleaner and more concise way to extract the type directly. See https://en.cppreference.com/w/cpp/types/underlying_type for details. -BEGIN VERIFY SCRIPT- sed -i -E 's/(typename )?(std::[a-z_]+)(<[^<>]+>)::type\b/\2_t\3/g' $(git grep -l '::type' ./src ':(exclude)src/bench/nanobench.h' ':(exclude)src/leveldb' ':(exclude)src/minisketch' ':(exclude)src/span.h' ':(exclude)src/sync.h') -END VERIFY SCRIPT-
This commit is contained in:
parent
5b8fd7c3a6
commit
8327889f35
@ -24,7 +24,7 @@ static_assert(!ValidDeployment(static_cast<Consensus::BuriedDeployment>(Consensu
|
||||
template<typename T, T x>
|
||||
static constexpr bool is_minimum()
|
||||
{
|
||||
using U = typename std::underlying_type<T>::type;
|
||||
using U = std::underlying_type_t<T>;
|
||||
return x == std::numeric_limits<U>::min();
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ enum class AddressPurpose;
|
||||
enum isminetype : unsigned int;
|
||||
struct CRecipient;
|
||||
struct WalletContext;
|
||||
using isminefilter = std::underlying_type<isminetype>::type;
|
||||
using isminefilter = std::underlying_type_t<isminetype>;
|
||||
} // namespace wallet
|
||||
|
||||
namespace interfaces {
|
||||
|
@ -48,7 +48,7 @@ enum class NetPermissionFlags : uint32_t {
|
||||
};
|
||||
static inline constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b)
|
||||
{
|
||||
using t = typename std::underlying_type<NetPermissionFlags>::type;
|
||||
using t = std::underlying_type_t<NetPermissionFlags>;
|
||||
return static_cast<NetPermissionFlags>(static_cast<t>(a) | static_cast<t>(b));
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ public:
|
||||
static std::vector<std::string> ToStrings(NetPermissionFlags flags);
|
||||
static inline bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
|
||||
{
|
||||
using t = typename std::underlying_type<NetPermissionFlags>::type;
|
||||
using t = std::underlying_type_t<NetPermissionFlags>;
|
||||
return (static_cast<t>(flags) & static_cast<t>(f)) == static_cast<t>(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<NetPermissionFlags>::type;
|
||||
using t = std::underlying_type_t<NetPermissionFlags>;
|
||||
flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f));
|
||||
}
|
||||
};
|
||||
|
@ -37,12 +37,12 @@ enum class ConnectionDirection {
|
||||
Both = (In | Out),
|
||||
};
|
||||
static inline ConnectionDirection& operator|=(ConnectionDirection& a, ConnectionDirection b) {
|
||||
using underlying = typename std::underlying_type<ConnectionDirection>::type;
|
||||
using underlying = std::underlying_type_t<ConnectionDirection>;
|
||||
a = ConnectionDirection(underlying(a) | underlying(b));
|
||||
return a;
|
||||
}
|
||||
static inline bool operator&(ConnectionDirection a, ConnectionDirection b) {
|
||||
using underlying = typename std::underlying_type<ConnectionDirection>::type;
|
||||
using underlying = std::underlying_type_t<ConnectionDirection>;
|
||||
return (underlying(a) & underlying(b));
|
||||
}
|
||||
|
||||
|
@ -70,10 +70,10 @@ namespace {
|
||||
*/
|
||||
template<typename T>
|
||||
CSHA512& operator<<(CSHA512& hasher, const T& data) {
|
||||
static_assert(!std::is_same<typename std::decay<T>::type, char*>::value, "Calling operator<<(CSHA512, char*) is probably not what you want");
|
||||
static_assert(!std::is_same<typename std::decay<T>::type, unsigned char*>::value, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want");
|
||||
static_assert(!std::is_same<typename std::decay<T>::type, const char*>::value, "Calling operator<<(CSHA512, const char*) is probably not what you want");
|
||||
static_assert(!std::is_same<typename std::decay<T>::type, const unsigned char*>::value, "Calling operator<<(CSHA512, const unsigned char*) is probably not what you want");
|
||||
static_assert(!std::is_same<std::decay_t<T>, char*>::value, "Calling operator<<(CSHA512, char*) is probably not what you want");
|
||||
static_assert(!std::is_same<std::decay_t<T>, unsigned char*>::value, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want");
|
||||
static_assert(!std::is_same<std::decay_t<T>, const char*>::value, "Calling operator<<(CSHA512, const char*) is probably not what you want");
|
||||
static_assert(!std::is_same<std::decay_t<T>, const unsigned char*>::value, "Calling operator<<(CSHA512, const unsigned char*) is probably not what you want");
|
||||
hasher.Write((const unsigned char*)&data, sizeof(data));
|
||||
return hasher;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hu
|
||||
std::string GetAllOutputTypes()
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
using U = std::underlying_type<TxoutType>::type;
|
||||
using U = std::underlying_type_t<TxoutType>;
|
||||
for (U i = (U)TxoutType::NONSTANDARD; i <= (U)TxoutType::WITNESS_UNKNOWN; ++i) {
|
||||
ret.emplace_back(GetTxnOutputType(static_cast<TxoutType>(i)));
|
||||
}
|
||||
|
@ -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>::type& obj) { code; })
|
||||
#define SER_READ(obj, code) ser_action.SerRead(s, obj, [&](Stream& s, std::remove_const_t<Type>& obj) { code; })
|
||||
#define SER_WRITE(obj, code) ser_action.SerWrite(s, obj, [&](Stream& s, const Type& obj) { code; })
|
||||
|
||||
/**
|
||||
@ -507,12 +507,12 @@ struct VarIntFormatter
|
||||
{
|
||||
template<typename Stream, typename I> void Ser(Stream &s, I v)
|
||||
{
|
||||
WriteVarInt<Stream,Mode,typename std::remove_cv<I>::type>(s, v);
|
||||
WriteVarInt<Stream,Mode,std::remove_cv_t<I>>(s, v);
|
||||
}
|
||||
|
||||
template<typename Stream, typename I> void Unser(Stream& s, I& v)
|
||||
{
|
||||
v = ReadVarInt<Stream,Mode,typename std::remove_cv<I>::type>(s);
|
||||
v = ReadVarInt<Stream,Mode,std::remove_cv_t<I>>(s);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -134,7 +134,7 @@ template <typename WeakEnumType, size_t size>
|
||||
{
|
||||
return fuzzed_data_provider.ConsumeBool() ?
|
||||
fuzzed_data_provider.PickValueInArray<WeakEnumType>(all_types) :
|
||||
WeakEnumType(fuzzed_data_provider.ConsumeIntegral<typename std::underlying_type<WeakEnumType>::type>());
|
||||
WeakEnumType(fuzzed_data_provider.ConsumeIntegral<std::underlying_type_t<WeakEnumType>>());
|
||||
}
|
||||
|
||||
[[nodiscard]] inline opcodetype ConsumeOpcodeType(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
|
@ -20,9 +20,9 @@
|
||||
* (list initialization always copies).
|
||||
*/
|
||||
template<typename... Args>
|
||||
inline std::vector<typename std::common_type<Args...>::type> Vector(Args&&... args)
|
||||
inline std::vector<std::common_type_t<Args...>> Vector(Args&&... args)
|
||||
{
|
||||
std::vector<typename std::common_type<Args...>::type> ret;
|
||||
std::vector<std::common_type_t<Args...>> 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<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...};
|
||||
|
@ -48,7 +48,7 @@ enum isminetype : unsigned int {
|
||||
ISMINE_ENUM_ELEMENTS,
|
||||
};
|
||||
/** used for bitflags of isminetype */
|
||||
using isminefilter = std::underlying_type<isminetype>::type;
|
||||
using isminefilter = std::underlying_type_t<isminetype>;
|
||||
|
||||
/**
|
||||
* Address purpose field that has been been stored with wallet sending and
|
||||
|
Loading…
x
Reference in New Issue
Block a user