Skip to content

Commit 302ced7

Browse files
committed
Misc: use concepts instead of SFINAE
1 parent 600ac6e commit 302ced7

File tree

9 files changed

+54
-44
lines changed

9 files changed

+54
-44
lines changed

common/EnumOps.h

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
// Template function for casting enumerations to their underlying type
99
template <typename Enumeration>
10-
typename std::underlying_type<Enumeration>::type enum_cast(Enumeration E)
10+
std::underlying_type_t<Enumeration> enum_cast(Enumeration E)
1111
{
12-
return static_cast<typename std::underlying_type<Enumeration>::type>(E);
12+
return static_cast<typename std::underlying_type_t<Enumeration>>(E);
1313
}
1414

1515
namespace detail
@@ -25,67 +25,67 @@ namespace detail
2525
Enum value;
2626
constexpr enum_bool_helper(Enum value): value(value) {}
2727
constexpr operator Enum() const { return value; }
28-
constexpr operator bool() const { return static_cast<bool>(static_cast<typename std::underlying_type<Enum>::type>(value)); }
28+
constexpr operator bool() const { return static_cast<bool>(static_cast<std::underlying_type_t<Enum>>(value)); }
2929
};
3030
};
3131

3232
#define MARK_ENUM_AS_FLAGS(T) template<> struct detail::enum_is_flags<T> : public std::true_type {}
3333

3434
template <typename Enum>
35-
constexpr typename std::enable_if<detail::enum_is_flags<Enum>::value, Enum>::type
36-
operator|(Enum lhs, Enum rhs) noexcept
35+
requires detail::enum_is_flags<Enum>::value
36+
constexpr Enum operator|(Enum lhs, Enum rhs) noexcept
3737
{
38-
using underlying = typename std::underlying_type<Enum>::type;
38+
using underlying = std::underlying_type_t<Enum>;
3939
return static_cast<Enum>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
4040
}
4141

4242
template <typename Enum>
43-
constexpr typename std::enable_if<detail::enum_is_flags<Enum>::value, detail::enum_bool_helper<Enum>>::type
44-
operator&(Enum lhs, Enum rhs) noexcept
43+
requires detail::enum_is_flags<Enum>::value
44+
constexpr detail::enum_bool_helper<Enum> operator&(Enum lhs, Enum rhs) noexcept
4545
{
46-
using underlying = typename std::underlying_type<Enum>::type;
46+
using underlying = std::underlying_type_t<Enum>;
4747
return static_cast<Enum>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
4848
}
4949

5050
template <typename Enum>
51-
constexpr typename std::enable_if<detail::enum_is_flags<Enum>::value, Enum>::type
52-
operator^(Enum lhs, Enum rhs) noexcept
51+
requires detail::enum_is_flags<Enum>::value
52+
constexpr Enum operator^(Enum lhs, Enum rhs) noexcept
5353
{
54-
using underlying = typename std::underlying_type<Enum>::type;
54+
using underlying = std::underlying_type_t<Enum>;
5555
return static_cast<Enum>(static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
5656
}
5757

5858
template <typename Enum>
59-
constexpr typename std::enable_if<detail::enum_is_flags<Enum>::value, Enum&>::type
60-
operator|=(Enum& lhs, Enum rhs) noexcept
59+
requires detail::enum_is_flags<Enum>::value
60+
constexpr Enum& operator|=(Enum& lhs, Enum rhs) noexcept
6161
{
6262
return lhs = lhs | rhs;
6363
}
6464

6565
template <typename Enum>
66-
constexpr typename std::enable_if<detail::enum_is_flags<Enum>::value, Enum&>::type
67-
operator&=(Enum& lhs, Enum rhs) noexcept
66+
requires detail::enum_is_flags<Enum>::value
67+
constexpr Enum& operator&=(Enum& lhs, Enum rhs) noexcept
6868
{
6969
return lhs = lhs & rhs;
7070
}
7171

7272
template <typename Enum>
73-
constexpr typename std::enable_if<detail::enum_is_flags<Enum>::value, Enum&>::type
74-
operator^=(Enum& lhs, Enum rhs) noexcept
73+
requires detail::enum_is_flags<Enum>::value
74+
constexpr Enum& operator^=(Enum& lhs, Enum rhs) noexcept
7575
{
7676
return lhs = lhs ^ rhs;
7777
}
7878

79-
template<typename Enum>
80-
constexpr typename std::enable_if<detail::enum_is_flags<Enum>::value, bool>::type
81-
operator!(Enum e) noexcept
79+
template <typename Enum>
80+
requires detail::enum_is_flags<Enum>::value
81+
constexpr bool operator!(Enum e) noexcept
8282
{
83-
return !static_cast<typename std::underlying_type<Enum>::type>(e);
83+
return !static_cast<std::underlying_type_t<Enum>>(e);
8484
}
8585

86-
template<typename Enum>
87-
constexpr typename std::enable_if<detail::enum_is_flags<Enum>::value, Enum>::type
88-
operator~(Enum e) noexcept
86+
template <typename Enum>
87+
requires detail::enum_is_flags<Enum>::value
88+
constexpr Enum operator~(Enum e) noexcept
8989
{
90-
return static_cast<Enum>(~static_cast<typename std::underlying_type<Enum>::type>(e));
90+
return static_cast<Enum>(~static_cast<std::underlying_type_t<Enum>>(e));
9191
}

common/Error.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// Platform-specific includes
1515
#if defined(_WIN32)
1616
#include "RedtapeWindows.h"
17-
static_assert(std::is_same<DWORD, unsigned long>::value, "DWORD is unsigned long");
18-
static_assert(std::is_same<HRESULT, long>::value, "HRESULT is long");
17+
static_assert(std::is_same_v<DWORD, unsigned long>, "DWORD is unsigned long");
18+
static_assert(std::is_same_v<HRESULT, long>, "HRESULT is long");
1919
#endif
2020

2121
Error::Error() = default;

common/StringUtil.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ namespace StringUtil
7575
}
7676

7777
/// Wrapper around std::from_chars
78-
template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
78+
template <typename T>
79+
requires std::is_integral_v<T>
7980
inline std::optional<T> FromChars(const std::string_view str, int base = 10)
8081
{
8182
T value;
@@ -86,7 +87,8 @@ namespace StringUtil
8687

8788
return value;
8889
}
89-
template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
90+
template <typename T>
91+
requires std::is_integral_v<T>
9092
inline std::optional<T> FromChars(const std::string_view str, int base, std::string_view* endptr)
9193
{
9294
T value;
@@ -103,7 +105,8 @@ namespace StringUtil
103105
return value;
104106
}
105107

106-
template <typename T, std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
108+
template <typename T>
109+
requires std::is_floating_point_v<T>
107110
inline std::optional<T> FromChars(const std::string_view str)
108111
{
109112
T value;
@@ -114,7 +117,8 @@ namespace StringUtil
114117

115118
return value;
116119
}
117-
template <typename T, std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
120+
template <typename T>
121+
requires std::is_floating_point_v<T>
118122
inline std::optional<T> FromChars(const std::string_view str, std::string_view* endptr)
119123
{
120124
T value;
@@ -132,7 +136,8 @@ namespace StringUtil
132136
}
133137

134138
/// Wrapper around std::to_chars
135-
template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
139+
template <typename T>
140+
requires std::is_integral_v<T>
136141
inline std::string ToChars(T value, int base = 10)
137142
{
138143
// to_chars() requires macOS 10.15+.
@@ -154,7 +159,8 @@ namespace StringUtil
154159
#endif
155160
}
156161

157-
template <typename T, std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
162+
template <typename T>
163+
requires std::is_floating_point_v<T>
158164
inline std::string ToChars(T value)
159165
{
160166
// No to_chars() in older versions of libstdc++/libc++.

common/emitter/x86types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace x86Emitter
4444
template <typename T>
4545
static __fi bool is_s8(T imm)
4646
{
47-
return (s8)imm == (typename std::make_signed<T>::type)imm;
47+
return (s8)imm == (std::make_signed_t<T>)imm;
4848
}
4949

5050
template <typename T>

pcsx2/GS/GSLzma.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ namespace GSDumpTypes
120120
#undef DEF_GIFReg
121121
// clang-format on
122122

123-
template <typename Output, typename Input, typename std::enable_if<sizeof(Input) == sizeof(Output), bool>::type = true>
123+
template <typename Output, typename Input>
124+
requires(sizeof(Input) == sizeof(Output))
124125
static constexpr Output BitCast(Input input)
125126
{
126127
Output output;

pcsx2/GS/GSRingHeap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class GSRingHeap
262262
template <typename T>
263263
typename _unique_if<T>::_unique_array_unknown_bound make_unique(size_t count)
264264
{
265-
typedef typename std::remove_extent<T>::type Base;
265+
typedef std::remove_extent_t<T> Base;
266266
return UniquePtr<T>(make_array<Base>(count));
267267
}
268268

pcsx2/GS/Renderers/SW/GSDrawScanlineCodeGenerator.all.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class GSDrawScanlineCodeGenerator : public GSNewCodeGenerator
2525
{
2626
using XYm = DRAW_SCANLINE_VECTOR_REGISTER;
2727

28-
constexpr static bool isXmm = std::is_same<XYm, Xbyak::Xmm>::value;
29-
constexpr static bool isYmm = std::is_same<XYm, Xbyak::Ymm>::value;
28+
constexpr static bool isXmm = std::is_same_v<XYm, Xbyak::Xmm>;
29+
constexpr static bool isYmm = std::is_same_v<XYm, Xbyak::Ymm>;
3030
constexpr static int wordsize = 8;
3131
constexpr static int vecsize = isXmm ? 16 : 32;
3232
constexpr static int vecsizelog = isXmm ? 4 : 5;

pcsx2/GS/Renderers/SW/GSSetupPrimCodeGenerator.all.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class GSSetupPrimCodeGenerator : public GSNewCodeGenerator
2626
using Xmm = Xbyak::Xmm;
2727
using Ymm = Xbyak::Ymm;
2828

29-
constexpr static bool isXmm = std::is_same<XYm, Xbyak::Xmm>::value;
30-
constexpr static bool isYmm = std::is_same<XYm, Xbyak::Ymm>::value;
29+
constexpr static bool isXmm = std::is_same_v<XYm, Xbyak::Xmm>;
30+
constexpr static bool isYmm = std::is_same_v<XYm, Xbyak::Ymm>;
3131
constexpr static int vecsize = isXmm ? 16 : 32;
3232

3333
constexpr static int dsize = isXmm ? 4 : 8;

pcsx2/StateWrapper.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class StateWrapper
104104
u32 GetVersion() const { return m_version; }
105105

106106
/// Overload for integral or floating-point types. Writes bytes as-is.
107-
template <typename T, std::enable_if_t<std::is_integral_v<T> || std::is_floating_point_v<T>, int> = 0>
107+
template <typename T>
108+
requires std::is_integral_v<T> || std::is_floating_point_v<T>
108109
void Do(T* value_ptr)
109110
{
110111
if (m_mode == Mode::Read)
@@ -120,7 +121,8 @@ class StateWrapper
120121
}
121122

122123
/// Overload for enum types. Uses the underlying type.
123-
template <typename T, std::enable_if_t<std::is_enum_v<T>, int> = 0>
124+
template <typename T>
125+
requires std::is_enum_v<T>
124126
void Do(T* value_ptr)
125127
{
126128
using TType = std::underlying_type_t<T>;
@@ -142,7 +144,8 @@ class StateWrapper
142144
}
143145

144146
/// Overload for POD types, such as structs.
145-
template <typename T, std::enable_if_t<std::is_standard_layout_v<T> && std::is_trivial_v<T>, int> = 0>
147+
template <typename T>
148+
requires std::is_standard_layout_v<T> && std::is_trivial_v<T>
146149
void DoPOD(T* value_ptr)
147150
{
148151
if (m_mode == Mode::Read)

0 commit comments

Comments
 (0)