refactor: modernize remaining outdated trait patterns

This commit is contained in:
Lőrinc 2025-02-19 13:42:03 +01:00
parent ab2b67fce2
commit 4cd95a2921
4 changed files with 12 additions and 12 deletions

View File

@ -334,7 +334,7 @@ public:
/** Generate a uniform random duration in the range [0..max). Precondition: max.count() > 0 */
template <StdChronoDuration Dur>
Dur randrange(typename std::common_type_t<Dur> range) noexcept
Dur randrange(std::common_type_t<Dur> 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

View File

@ -70,10 +70,10 @@ namespace {
*/
template<typename T>
CSHA512& operator<<(CSHA512& hasher, const T& data) {
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");
static_assert(!std::is_same_v<std::decay_t<T>, char*>, "Calling operator<<(CSHA512, char*) is probably not what you want");
static_assert(!std::is_same_v<std::decay_t<T>, unsigned char*>, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want");
static_assert(!std::is_same_v<std::decay_t<T>, const char*>, "Calling operator<<(CSHA512, const char*) is probably not what you want");
static_assert(!std::is_same_v<std::decay_t<T>, 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;
}

View File

@ -220,13 +220,13 @@ const Out& AsBase(const In& x)
template <typename Stream> \
void Serialize(Stream& s) const \
{ \
static_assert(std::is_same_v<const cls&, decltype(*this)>, "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_v<cls&, decltype(*this)>, "Unserialize type mismatch"); \
static_assert(std::is_same_v<cls&, decltype(*this)>, "Unserialize type mismatch"); \
Unser(s, *this); \
}
@ -507,12 +507,12 @@ struct VarIntFormatter
{
template<typename Stream, typename I> void Ser(Stream &s, I v)
{
WriteVarInt<Stream,Mode,std::remove_cv_t<I>>(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,std::remove_cv_t<I>>(s);
v = ReadVarInt<Stream,Mode, std::remove_cv_t<I>>(s);
}
};
@ -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_v<I>, std::underlying_type<I>, std::common_type<I>>::type::type;
using U = typename std::conditional_t<std::is_enum_v<I>, std::underlying_type<I>, std::common_type<I>>::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) {

View File

@ -277,8 +277,8 @@ template <typename T> T FuzzedDataProvider::ConsumeProbability() {
// 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<T>(ConsumeIntegral<IntegralType>());
result /= static_cast<T>(std::numeric_limits<IntegralType>::max());