Actually use enable_if correctly
This commit is contained in:
parent
984b67eb96
commit
433615ff0d
@ -4,10 +4,10 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
template<typename T, typename = std::enable_if<std::is_arithmetic_v<T>, void>>
|
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
|
||||||
struct Rect;
|
struct Rect;
|
||||||
|
|
||||||
template<typename T, typename = std::enable_if<std::is_arithmetic_v<T>, void>>
|
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
|
||||||
struct Vec2
|
struct Vec2
|
||||||
{
|
{
|
||||||
T X, Y;
|
T X, Y;
|
||||||
@ -18,7 +18,7 @@ struct Vec2
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename S, typename = std::enable_if<std::is_constructible_v<T, S>, void>>
|
template<typename S, typename = std::enable_if_t<std::is_constructible_v<T, S>>>
|
||||||
constexpr explicit Vec2(Vec2<S> other):
|
constexpr explicit Vec2(Vec2<S> other):
|
||||||
X(other.X),
|
X(other.X),
|
||||||
Y(other.Y)
|
Y(other.Y)
|
||||||
@ -52,13 +52,13 @@ struct Vec2
|
|||||||
return Vec2<decltype(std::declval<T>() - std::declval<S>())>(X - other.X, Y - other.Y);
|
return Vec2<decltype(std::declval<T>() - std::declval<S>())>(X - other.X, Y - other.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename S, typename = std::enable_if<std::is_arithmetic_v<S>, void>>
|
template<typename S, typename = std::enable_if_t<std::is_arithmetic_v<S>>>
|
||||||
constexpr inline Vec2<decltype(std::declval<T>() * std::declval<S>())> operator*(S other) const
|
constexpr inline Vec2<decltype(std::declval<T>() * std::declval<S>())> operator*(S other) const
|
||||||
{
|
{
|
||||||
return Vec2<decltype(std::declval<T>() * std::declval<S>())>(X * other, Y * other);
|
return Vec2<decltype(std::declval<T>() * std::declval<S>())>(X * other, Y * other);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename S, typename = std::enable_if<std::is_arithmetic_v<S>, void>>
|
template<typename S, typename = std::enable_if_t<std::is_arithmetic_v<S>>>
|
||||||
constexpr inline Vec2<decltype(std::declval<T>() / std::declval<S>())> operator/(S other) const
|
constexpr inline Vec2<decltype(std::declval<T>() / std::declval<S>())> operator/(S other) const
|
||||||
{
|
{
|
||||||
return Vec2<decltype(std::declval<T>() / std::declval<S>())>(X / other, Y / other);
|
return Vec2<decltype(std::declval<T>() / std::declval<S>())>(X / other, Y / other);
|
||||||
@ -94,7 +94,7 @@ struct Vec2
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return a rectangle starting at origin, whose dimensions match this vector
|
// Return a rectangle starting at origin, whose dimensions match this vector
|
||||||
template<typename = std::enable_if<std::is_integral_v<T>, void>>
|
template<typename S = T, typename = std::enable_if_t<std::is_integral_v<S>>>
|
||||||
constexpr inline Rect<T> OriginRect() const
|
constexpr inline Rect<T> OriginRect() const
|
||||||
{
|
{
|
||||||
return RectSized(Vec2<T>(0, 0), *this);
|
return RectSized(Vec2<T>(0, 0), *this);
|
||||||
@ -106,7 +106,7 @@ struct Vec2
|
|||||||
template<typename T, typename V>
|
template<typename T, typename V>
|
||||||
Vec2<T> Vec2<T, V>::Zero = Vec2<T>(0, 0);
|
Vec2<T> Vec2<T, V>::Zero = Vec2<T>(0, 0);
|
||||||
|
|
||||||
template<typename T, typename = std::enable_if<std::is_arithmetic_v<T>, void>>
|
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
|
||||||
struct Mat2
|
struct Mat2
|
||||||
{
|
{
|
||||||
// ⎛A B⎞
|
// ⎛A B⎞
|
||||||
@ -149,7 +149,7 @@ Mat2<T> Mat2<T, V>::MirrorY = Mat2<T>(1, 0, 0, -1);
|
|||||||
template<typename T, typename V>
|
template<typename T, typename V>
|
||||||
Mat2<T> Mat2<T, V>::CCW = Mat2<T>(0, 1, -1, 0); // reminder: the Y axis points down
|
Mat2<T> Mat2<T, V>::CCW = Mat2<T>(0, 1, -1, 0); // reminder: the Y axis points down
|
||||||
|
|
||||||
template<typename T, typename = std::enable_if<std::is_arithmetic_v<T>, void>>
|
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
|
||||||
constexpr static inline Rect<T> RectBetween(Vec2<T>, Vec2<T>);
|
constexpr static inline Rect<T> RectBetween(Vec2<T>, Vec2<T>);
|
||||||
|
|
||||||
template<typename T, typename>
|
template<typename T, typename>
|
||||||
@ -236,7 +236,7 @@ public:
|
|||||||
return point.X >= TopLeft.X && point.X <= BottomRight.X && point.Y >= TopLeft.Y && point.Y <= BottomRight.Y;
|
return point.X >= TopLeft.X && point.X <= BottomRight.X && point.Y >= TopLeft.Y && point.Y <= BottomRight.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename = std::enable_if<std::is_integral_v<T>, void>>
|
template<typename S = T, typename = std::enable_if_t<std::is_integral_v<S>>>
|
||||||
inline Vec2<T> Size() const
|
inline Vec2<T> Size() const
|
||||||
{
|
{
|
||||||
return BottomRight - TopLeft + Vec2<T>(1, 1);
|
return BottomRight - TopLeft + Vec2<T>(1, 1);
|
||||||
@ -259,13 +259,13 @@ constexpr static inline Rect<T> RectBetween(Vec2<T> topLeft, Vec2<T> bottomRight
|
|||||||
return Rect<T>(topLeft, bottomRight);
|
return Rect<T>(topLeft, bottomRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename = std::enable_if<std::is_arithmetic_v<T>, void>>
|
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
|
||||||
static inline Rect<T> RectAt(Vec2<T> pos)
|
static inline Rect<T> RectAt(Vec2<T> pos)
|
||||||
{
|
{
|
||||||
return RectBetween<T>(pos, pos);
|
return RectBetween<T>(pos, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename = std::enable_if<std::is_integral_v<T>, void>>
|
template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
|
||||||
constexpr static inline Rect<T> RectSized(Vec2<T> topLeft, Vec2<T> dimen)
|
constexpr static inline Rect<T> RectSized(Vec2<T> topLeft, Vec2<T> dimen)
|
||||||
{
|
{
|
||||||
return RectBetween<T>(topLeft, topLeft + dimen - Vec2<T>(1, 1));
|
return RectBetween<T>(topLeft, topLeft + dimen - Vec2<T>(1, 1));
|
||||||
|
@ -32,11 +32,11 @@ constexpr int PIXB(pixel x)
|
|||||||
return x & 0xFF;
|
return x & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename = std::enable_if<std::is_arithmetic_v<T>, void>>
|
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
|
||||||
class RGBA;
|
class RGBA;
|
||||||
|
|
||||||
template<typename T, typename = std::enable_if<std::is_arithmetic_v<T>, void>>
|
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
|
||||||
struct alignas(std::min(alignof(uint32_t), alignof(T))) RGB
|
struct alignas(alignof(uint32_t) > alignof(T) ? alignof(uint32_t) : alignof(T)) RGB
|
||||||
{
|
{
|
||||||
T Blue, Green, Red;
|
T Blue, Green, Red;
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ struct alignas(std::min(alignof(uint32_t), alignof(T))) RGB
|
|||||||
template<typename S> // Avoid referring to the non-intuitive order of components
|
template<typename S> // Avoid referring to the non-intuitive order of components
|
||||||
RGB(std::initializer_list<S>) = delete;
|
RGB(std::initializer_list<S>) = delete;
|
||||||
|
|
||||||
template<typename = std::enable_if<std::is_same_v<T, uint8_t>, void>>
|
template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
|
||||||
inline RGB<T> Blend(RGBA<T> other) const
|
inline RGB<T> Blend(RGBA<T> other) const
|
||||||
{
|
{
|
||||||
if (other.Alpha == 0xFF)
|
if (other.Alpha == 0xFF)
|
||||||
@ -63,7 +63,7 @@ struct alignas(std::min(alignof(uint32_t), alignof(T))) RGB
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename = std::enable_if<std::is_same_v<T, uint8_t>, void>>
|
template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
|
||||||
inline RGB<T> Add(RGBA<T> other) const
|
inline RGB<T> Add(RGBA<T> other) const
|
||||||
{
|
{
|
||||||
return RGB<T>(
|
return RGB<T>(
|
||||||
@ -73,7 +73,7 @@ struct alignas(std::min(alignof(uint32_t), alignof(T))) RGB
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename = std::enable_if<std::is_same_v<T, uint8_t>, void>>
|
template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
|
||||||
inline RGB<T> Inverse() const
|
inline RGB<T> Inverse() const
|
||||||
{
|
{
|
||||||
return RGB<T>(0xFF - Red, 0xFF - Green, 0xFF - Blue);
|
return RGB<T>(0xFF - Red, 0xFF - Green, 0xFF - Blue);
|
||||||
@ -84,13 +84,13 @@ struct alignas(std::min(alignof(uint32_t), alignof(T))) RGB
|
|||||||
return RGBA<T>(Red, Green, Blue, a);
|
return RGBA<T>(Red, Green, Blue, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename = std::enable_if<std::is_same_v<T, uint8_t>, void>>
|
template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
|
||||||
inline pixel Pack() const
|
inline pixel Pack() const
|
||||||
{
|
{
|
||||||
return PIXRGB(Red, Green, Blue);
|
return PIXRGB(Red, Green, Blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename = std::enable_if<std::is_same_v<T, uint8_t>, void>>
|
template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
|
||||||
static inline RGB<T> Unpack(pixel px)
|
static inline RGB<T> Unpack(pixel px)
|
||||||
{
|
{
|
||||||
return RGB<T>(PIXR(px), PIXG(px), PIXB(px));
|
return RGB<T>(PIXR(px), PIXG(px), PIXB(px));
|
||||||
@ -98,7 +98,7 @@ struct alignas(std::min(alignof(uint32_t), alignof(T))) RGB
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T, typename>
|
template<typename T, typename>
|
||||||
struct alignas(std::min(alignof(uint32_t), alignof(T))) RGBA
|
struct alignas(alignof(uint32_t) > alignof(T) ? alignof(uint32_t) : alignof(T)) RGBA
|
||||||
{
|
{
|
||||||
T Blue, Green, Red, Alpha;
|
T Blue, Green, Red, Alpha;
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ struct alignas(std::min(alignof(uint32_t), alignof(T))) RGBA
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename = std::enable_if<std::is_same_v<T, uint8_t>, void>>
|
template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
|
||||||
RGBA(T r, T g, T b):
|
RGBA(T r, T g, T b):
|
||||||
Blue(b),
|
Blue(b),
|
||||||
Green(g),
|
Green(g),
|
||||||
|
Reference in New Issue
Block a user