Skip to content

Commit 8327889

Browse files
committed
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-
1 parent 5b8fd7c commit 8327889

File tree

10 files changed

+19
-19
lines changed

10 files changed

+19
-19
lines changed

src/deploymentstatus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static_assert(!ValidDeployment(static_cast<Consensus::BuriedDeployment>(Consensu
2424
template<typename T, T x>
2525
static constexpr bool is_minimum()
2626
{
27-
using U = typename std::underlying_type<T>::type;
27+
using U = std::underlying_type_t<T>;
2828
return x == std::numeric_limits<U>::min();
2929
}
3030

src/interfaces/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum class AddressPurpose;
4545
enum isminetype : unsigned int;
4646
struct CRecipient;
4747
struct WalletContext;
48-
using isminefilter = std::underlying_type<isminetype>::type;
48+
using isminefilter = std::underlying_type_t<isminetype>;
4949
} // namespace wallet
5050

5151
namespace interfaces {

src/net_permissions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum class NetPermissionFlags : uint32_t {
4848
};
4949
static inline constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b)
5050
{
51-
using t = typename std::underlying_type<NetPermissionFlags>::type;
51+
using t = std::underlying_type_t<NetPermissionFlags>;
5252
return static_cast<NetPermissionFlags>(static_cast<t>(a) | static_cast<t>(b));
5353
}
5454

@@ -59,7 +59,7 @@ class NetPermissions
5959
static std::vector<std::string> ToStrings(NetPermissionFlags flags);
6060
static inline bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
6161
{
62-
using t = typename std::underlying_type<NetPermissionFlags>::type;
62+
using t = std::underlying_type_t<NetPermissionFlags>;
6363
return (static_cast<t>(flags) & static_cast<t>(f)) == static_cast<t>(f);
6464
}
6565
static inline void AddFlag(NetPermissionFlags& flags, NetPermissionFlags f)
@@ -74,7 +74,7 @@ class NetPermissions
7474
static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f)
7575
{
7676
assert(f == NetPermissionFlags::Implicit);
77-
using t = typename std::underlying_type<NetPermissionFlags>::type;
77+
using t = std::underlying_type_t<NetPermissionFlags>;
7878
flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f));
7979
}
8080
};

src/netbase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ enum class ConnectionDirection {
3737
Both = (In | Out),
3838
};
3939
static inline ConnectionDirection& operator|=(ConnectionDirection& a, ConnectionDirection b) {
40-
using underlying = typename std::underlying_type<ConnectionDirection>::type;
40+
using underlying = std::underlying_type_t<ConnectionDirection>;
4141
a = ConnectionDirection(underlying(a) | underlying(b));
4242
return a;
4343
}
4444
static inline bool operator&(ConnectionDirection a, ConnectionDirection b) {
45-
using underlying = typename std::underlying_type<ConnectionDirection>::type;
45+
using underlying = std::underlying_type_t<ConnectionDirection>;
4646
return (underlying(a) & underlying(b));
4747
}
4848

src/randomenv.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ namespace {
7070
*/
7171
template<typename T>
7272
CSHA512& operator<<(CSHA512& hasher, const T& data) {
73-
static_assert(!std::is_same<typename std::decay<T>::type, char*>::value, "Calling operator<<(CSHA512, char*) is probably not what you want");
74-
static_assert(!std::is_same<typename std::decay<T>::type, unsigned char*>::value, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want");
75-
static_assert(!std::is_same<typename std::decay<T>::type, const char*>::value, "Calling operator<<(CSHA512, const char*) is probably not what you want");
76-
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");
73+
static_assert(!std::is_same<std::decay_t<T>, char*>::value, "Calling operator<<(CSHA512, char*) is probably not what you want");
74+
static_assert(!std::is_same<std::decay_t<T>, unsigned char*>::value, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want");
75+
static_assert(!std::is_same<std::decay_t<T>, const char*>::value, "Calling operator<<(CSHA512, const char*) is probably not what you want");
76+
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");
7777
hasher.Write((const unsigned char*)&data, sizeof(data));
7878
return hasher;
7979
}

src/rpc/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hu
4949
std::string GetAllOutputTypes()
5050
{
5151
std::vector<std::string> ret;
52-
using U = std::underlying_type<TxoutType>::type;
52+
using U = std::underlying_type_t<TxoutType>;
5353
for (U i = (U)TxoutType::NONSTANDARD; i <= (U)TxoutType::WITNESS_UNKNOWN; ++i) {
5454
ret.emplace_back(GetTxnOutputType(static_cast<TxoutType>(i)));
5555
}

src/serialize.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const Out& AsBase(const In& x)
154154
}
155155

156156
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
157-
#define SER_READ(obj, code) ser_action.SerRead(s, obj, [&](Stream& s, typename std::remove_const<Type>::type& obj) { code; })
157+
#define SER_READ(obj, code) ser_action.SerRead(s, obj, [&](Stream& s, std::remove_const_t<Type>& obj) { code; })
158158
#define SER_WRITE(obj, code) ser_action.SerWrite(s, obj, [&](Stream& s, const Type& obj) { code; })
159159

160160
/**
@@ -507,12 +507,12 @@ struct VarIntFormatter
507507
{
508508
template<typename Stream, typename I> void Ser(Stream &s, I v)
509509
{
510-
WriteVarInt<Stream,Mode,typename std::remove_cv<I>::type>(s, v);
510+
WriteVarInt<Stream,Mode,std::remove_cv_t<I>>(s, v);
511511
}
512512

513513
template<typename Stream, typename I> void Unser(Stream& s, I& v)
514514
{
515-
v = ReadVarInt<Stream,Mode,typename std::remove_cv<I>::type>(s);
515+
v = ReadVarInt<Stream,Mode,std::remove_cv_t<I>>(s);
516516
}
517517
};
518518

src/test/fuzz/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ template <typename WeakEnumType, size_t size>
134134
{
135135
return fuzzed_data_provider.ConsumeBool() ?
136136
fuzzed_data_provider.PickValueInArray<WeakEnumType>(all_types) :
137-
WeakEnumType(fuzzed_data_provider.ConsumeIntegral<typename std::underlying_type<WeakEnumType>::type>());
137+
WeakEnumType(fuzzed_data_provider.ConsumeIntegral<std::underlying_type_t<WeakEnumType>>());
138138
}
139139

140140
[[nodiscard]] inline opcodetype ConsumeOpcodeType(FuzzedDataProvider& fuzzed_data_provider) noexcept

src/util/vector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
* (list initialization always copies).
2121
*/
2222
template<typename... Args>
23-
inline std::vector<typename std::common_type<Args...>::type> Vector(Args&&... args)
23+
inline std::vector<std::common_type_t<Args...>> Vector(Args&&... args)
2424
{
25-
std::vector<typename std::common_type<Args...>::type> ret;
25+
std::vector<std::common_type_t<Args...>> ret;
2626
ret.reserve(sizeof...(args));
2727
// The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html
2828
(void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...};

src/wallet/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum isminetype : unsigned int {
4848
ISMINE_ENUM_ELEMENTS,
4949
};
5050
/** used for bitflags of isminetype */
51-
using isminefilter = std::underlying_type<isminetype>::type;
51+
using isminefilter = std::underlying_type_t<isminetype>;
5252

5353
/**
5454
* Address purpose field that has been been stored with wallet sending and

0 commit comments

Comments
 (0)