The "_t" and "_v" version of type traits should be used instead of "::type" and "::value".

This commit is contained in:
Roman Telezhynskyi 2024-02-21 09:05:13 +02:00
parent 634913da34
commit b6b278997a
5 changed files with 33 additions and 45 deletions

View File

@ -71,7 +71,7 @@ template <class T> inline auto CastTo(const QVector<T> &points, QVector<T> &cast
//---------------------------------------------------------------------------------------------------------------------
// upcast
template <class Derived, class Base, typename std::enable_if<std::is_base_of<Base, Derived>::value>::type * = nullptr>
template <class Derived, class Base, std::enable_if_t<std::is_base_of_v<Base, Derived>> * = nullptr>
inline auto CastTo(const QVector<Base> &points, QVector<Derived> &casted) -> void
{
casted.clear();
@ -84,7 +84,7 @@ inline auto CastTo(const QVector<Base> &points, QVector<Derived> &casted) -> voi
//---------------------------------------------------------------------------------------------------------------------
// downcast
template <class Base, class Derived, typename std::enable_if<std::is_base_of<Base, Derived>::value>::type * = nullptr>
template <class Base, class Derived, std::enable_if_t<std::is_base_of_v<Base, Derived>> * = nullptr>
inline auto CastTo(const QVector<Derived> &points, QVector<Base> &casted) -> void
{
casted.clear();

View File

@ -19,12 +19,12 @@ namespace fpm
//! \tparam FractionBits the number of bits of the BaseType used to store the fraction
template <typename BaseType, typename IntermediateType, unsigned int FractionBits> class fixed
{
static_assert(std::is_integral<BaseType>::value, "BaseType must be an integral type");
static_assert(std::is_integral_v<BaseType>, "BaseType must be an integral type");
static_assert(FractionBits > 0, "FractionBits must be greater than zero");
static_assert(FractionBits <= sizeof(BaseType) * 8 - 1, "BaseType must at least be able to contain entire "
"fraction, with space for at least one integral bit");
static_assert(sizeof(IntermediateType) > sizeof(BaseType), "IntermediateType must be larger than BaseType");
static_assert(std::is_signed<IntermediateType>::value == std::is_signed<BaseType>::value,
static_assert(std::is_signed_v<IntermediateType> == std::is_signed_v<BaseType>,
"IntermediateType must have same signedness as BaseType");
// Although this value fits in the BaseType in terms of bits, if there's only one integral bit, this value
@ -44,7 +44,7 @@ public:
// Converts an integral number to the fixed-point type.
// Like static_cast, this truncates bits that don't fit.
template <typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline explicit fixed(T val) noexcept
: m_value(static_cast<BaseType>(val * FRACTION_MULT))
{
@ -52,7 +52,7 @@ public:
// Converts an floating-point number to the fixed-point type.
// Like static_cast, this truncates bits that don't fit.
template <typename T, typename std::enable_if<std::is_floating_point<T>::value>::type * = nullptr>
template <typename T, std::enable_if_t<std::is_floating_point_v<T>> * = nullptr>
constexpr inline explicit fixed(T val) noexcept
: m_value(static_cast<BaseType>((val >= 0.0) ? (val * FRACTION_MULT + T{0.5}) : (val * FRACTION_MULT - T{0.5})))
{
@ -67,14 +67,14 @@ public:
}
// Explicit conversion to a floating-point type
template <typename T, typename std::enable_if<std::is_floating_point<T>::value>::type * = nullptr>
template <typename T, std::enable_if_t<std::is_floating_point_v<T>> * = nullptr>
constexpr inline explicit operator T() const noexcept
{
return static_cast<T>(m_value) / FRACTION_MULT;
}
// Explicit conversion to an integral type
template <typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline explicit operator T() const noexcept
{
return static_cast<T>(m_value / FRACTION_MULT);
@ -87,8 +87,7 @@ public:
//! Constructs a fixed-point number from another fixed-point number.
//! \tparam NumFractionBits the number of bits used by the fraction in \a value.
//! \param value the integer fixed-point number
template <unsigned int NumFractionBits, typename T,
typename std::enable_if<(NumFractionBits > FractionBits)>::type * = nullptr>
template <unsigned int NumFractionBits, typename T, std::enable_if_t<(NumFractionBits > FractionBits)> * = nullptr>
static constexpr inline auto from_fixed_point(T value) noexcept -> fixed
{
// To correctly round the last bit in the result, we need one more bit of information.
@ -98,8 +97,7 @@ public:
raw_construct_tag{});
}
template <unsigned int NumFractionBits, typename T,
typename std::enable_if<(NumFractionBits <= FractionBits)>::type * = nullptr>
template <unsigned int NumFractionBits, typename T, std::enable_if_t<(NumFractionBits <= FractionBits)> * = nullptr>
static constexpr inline auto from_fixed_point(T value) noexcept -> fixed
{
return fixed(static_cast<BaseType>(value * (T(1) << (FractionBits - NumFractionBits))), raw_construct_tag{});
@ -132,7 +130,7 @@ public:
return *this;
}
template <typename I, typename std::enable_if<std::is_integral<I>::value>::type * = nullptr>
template <typename I, std::enable_if_t<std::is_integral_v<I>> * = nullptr>
inline auto operator+=(I y) noexcept -> fixed &
{
m_value += y * FRACTION_MULT;
@ -145,7 +143,7 @@ public:
return *this;
}
template <typename I, typename std::enable_if<std::is_integral<I>::value>::type * = nullptr>
template <typename I, std::enable_if_t<std::is_integral_v<I>> * = nullptr>
inline auto operator-=(I y) noexcept -> fixed &
{
m_value -= y * FRACTION_MULT;
@ -163,7 +161,7 @@ public:
return *this;
}
template <typename I, typename std::enable_if<std::is_integral<I>::value>::type * = nullptr>
template <typename I, std::enable_if_t<std::is_integral_v<I>> * = nullptr>
inline auto operator*=(I y) noexcept -> fixed &
{
m_value *= y;
@ -181,7 +179,7 @@ public:
return *this;
}
template <typename I, typename std::enable_if<std::is_integral<I>::value>::type * = nullptr>
template <typename I, std::enable_if_t<std::is_integral_v<I>> * = nullptr>
inline auto operator/=(I y) noexcept -> fixed &
{
m_value /= y;
@ -192,14 +190,14 @@ public:
// Shift operators
//
template <typename I, typename std::enable_if<std::is_integral<I>::value>::type * = nullptr>
template <typename I, std::enable_if_t<std::is_integral_v<I>> * = nullptr>
inline auto operator>>=(I y) noexcept -> fixed &
{
m_value >>= y;
return *this;
}
template <typename I, typename std::enable_if<std::is_integral<I>::value>::type * = nullptr>
template <typename I, std::enable_if_t<std::is_integral_v<I>> * = nullptr>
inline auto operator<<=(I y) noexcept -> fixed &
{
m_value <<= y;
@ -228,15 +226,13 @@ constexpr inline auto operator+(const fixed<B, I, F> &x, const fixed<B, I, F> &y
return fixed<B, I, F>(x) += y;
}
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator+(const fixed<B, I, F> &x, T y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(x) += y;
}
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator+(T x, const fixed<B, I, F> &y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(y) += x;
@ -252,15 +248,13 @@ constexpr inline auto operator-(const fixed<B, I, F> &x, const fixed<B, I, F> &y
return fixed<B, I, F>(x) -= y;
}
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator-(const fixed<B, I, F> &x, T y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(x) -= y;
}
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator-(T x, const fixed<B, I, F> &y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(x) -= y;
@ -276,15 +270,13 @@ constexpr inline auto operator*(const fixed<B, I, F> &x, const fixed<B, I, F> &y
return fixed<B, I, F>(x) *= y;
}
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator*(const fixed<B, I, F> &x, T y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(x) *= y;
}
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator*(T x, const fixed<B, I, F> &y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(y) *= x;
@ -300,15 +292,13 @@ constexpr inline auto operator/(const fixed<B, I, F> &x, const fixed<B, I, F> &y
return fixed<B, I, F>(x) /= y;
}
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator/(const fixed<B, I, F> &x, T y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(x) /= y;
}
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator/(T x, const fixed<B, I, F> &y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(x) /= y;
@ -318,15 +308,13 @@ constexpr inline auto operator/(T x, const fixed<B, I, F> &y) noexcept -> fixed<
// Shift operators
//
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator>>(const fixed<B, I, F> &x, T y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(x) >>= y;
}
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename B, typename I, unsigned int F, typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
constexpr inline auto operator<<(const fixed<B, I, F> &x, T y) noexcept -> fixed<B, I, F>
{
return fixed<B, I, F>(x) <<= y;

View File

@ -251,7 +251,7 @@ inline auto modf(fixed<B, I, F> x, fixed<B, I, F> *iptr) noexcept -> fixed<B, I,
//
template <typename B, typename I, unsigned int F, typename T,
typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
std::enable_if_t<std::is_integral_v<T>> * = nullptr>
auto pow(fixed<B, I, F> base, T exp) noexcept -> fixed<B, I, F>
{
using Fixed = fixed<B, I, F>;

View File

@ -698,7 +698,7 @@ void AbstractTest::ReadPieceNodeValue(const QJsonObject &itemObject, VPieceNode
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T, typename std::enable_if<std::is_floating_point<T>::value>::type *>
template <typename T, std::enable_if_t<std::is_floating_point_v<T>> *>
void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
const QString &defaultValue)
{
@ -737,7 +737,7 @@ void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T, typename std::enable_if<std::is_enum<T>::value>::type *>
template <typename T, std::enable_if_t<std::is_enum_v<T>> *>
void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
const QString &defaultValue)
{
@ -776,7 +776,7 @@ void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T, typename std::enable_if<std::is_integral<T>::value>::type *>
template <typename T, std::enable_if_t<std::is_integral_v<T>> *>
void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
const QString &defaultValue)
{

View File

@ -114,13 +114,13 @@ protected:
static void PrepareDocument(const QString &json, QByteArray &data);
static void TestRoot(const QJsonObject &root, const QString &attribute, const QString &file);
template <typename T, typename std::enable_if<std::is_floating_point<T>::value>::type * = nullptr>
template <typename T, std::enable_if_t<std::is_floating_point_v<T>> * = nullptr>
static void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
const QString &defaultValue = QString());
template <typename T, typename std::enable_if<std::is_enum<T>::value>::type * = nullptr>
template <typename T, std::enable_if_t<std::is_enum_v<T>> * = nullptr>
static void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
const QString &defaultValue = QString());
template <typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
template <typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
static void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
const QString &defaultValue = QString());
static void ReadStringValue(const QJsonObject &itemObject, const QString &attribute, QString &value,