Skip to content

Commit 686cb41

Browse files
Use concepts instead of enable_if
1 parent 670b42b commit 686cb41

18 files changed

Lines changed: 184 additions & 234 deletions

include/rfl/Attribute.hpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,21 @@ struct Attribute {
3333
template <class U>
3434
Attribute(Attribute<U>&& _attr) : value_(_attr.get()) {}
3535

36-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
37-
bool>::type = true>
36+
template <class U>
37+
requires std::is_convertible_v<U, Type>
3838
Attribute(const U& _value) : value_(_value) {}
3939

40-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
41-
bool>::type = true>
40+
template <class U>
41+
requires std::is_convertible_v<U, Type>
4242
Attribute(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
4343

44-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
45-
bool>::type = true>
44+
template <class U>
45+
requires std::is_convertible_v<U, Type>
4646
Attribute(const Attribute<U>& _attr) : value_(_attr.value()) {}
4747

4848
/// Assigns the underlying object to its default value.
49-
template <class U = Type,
50-
typename std::enable_if<std::is_default_constructible_v<U>,
51-
bool>::type = true>
49+
template <class U = Type>
50+
requires std::is_default_constructible_v<U>
5251
Attribute(const Default&) : value_(Type()) {}
5352

5453
~Attribute() = default;
@@ -75,17 +74,16 @@ struct Attribute {
7574
}
7675

7776
/// Assigns the underlying object.
78-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
79-
bool>::type = true>
77+
template <class U>
78+
requires std::is_convertible_v<U, Type>
8079
auto& operator=(const U& _value) {
8180
value_ = _value;
8281
return *this;
8382
}
8483

8584
/// Assigns the underlying object to its default value.
86-
template <class U = Type,
87-
typename std::enable_if<std::is_default_constructible_v<U>,
88-
bool>::type = true>
85+
template <class U = Type>
86+
requires std::is_default_constructible_v<U>
8987
auto& operator=(const Default&) {
9088
value_ = Type();
9189
return *this;

include/rfl/Binary.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace rfl {
1313

1414
/// Used to define a field in the NamedTuple.
1515
template <class T>
16-
requires std::is_unsigned_v<T>
16+
requires std::is_unsigned_v<T>
1717
struct Binary {
1818
/// The underlying type.
1919
using Type = T;
@@ -36,16 +36,16 @@ struct Binary {
3636
template <class U>
3737
Binary(Binary<U>&& _other) : value_(_other.get()) {}
3838

39-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
40-
bool>::type = true>
39+
template <class U>
40+
requires std::is_convertible_v<U, Type>
4141
Binary(const U& _value) : value_(_value) {}
4242

43-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
44-
bool>::type = true>
43+
template <class U>
44+
requires std::is_convertible_v<U, Type>
4545
Binary(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
4646

47-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
48-
bool>::type = true>
47+
template <class U>
48+
requires std::is_convertible_v<U, Type>
4949
Binary(const Binary<U>& _other) : value_(_other.value()) {}
5050

5151
Binary(const std::string& _str)
@@ -69,8 +69,8 @@ struct Binary {
6969
}
7070

7171
/// Assigns the underlying object.
72-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
73-
bool>::type = true>
72+
template <class U>
73+
requires std::is_convertible_v<U, Type>
7474
auto& operator=(const U& _value) {
7575
value_ = _value;
7676
return *this;

include/rfl/DefaultVal.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,16 @@ struct DefaultVal {
7272
}
7373

7474
/// Assigns the underlying object.
75-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
76-
bool>::type = true>
75+
template <class U>
76+
requires std::is_convertible_v<U, Type>
7777
auto& operator=(const U& _value) {
7878
value_ = _value;
7979
return *this;
8080
}
8181

8282
/// Assigns the underlying object to its default value.
83-
template <class U = Type,
84-
typename std::enable_if<std::is_default_constructible_v<U>,
85-
bool>::type = true>
83+
template <class U = Type>
84+
requires std::is_default_constructible_v<U>
8685
auto& operator=(const Default&) {
8786
value_ = Type();
8887
return *this;

include/rfl/Description.hpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,22 @@ struct Description {
4242
template <class U>
4343
Description(Description<_description, U>&& _field) : value_(_field.get()) {}
4444

45-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
46-
bool>::type = true>
45+
template <class U>
46+
requires std::is_convertible_v<U, Type>
4747
Description(const U& _value) : value_(_value) {}
4848

49-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
50-
bool>::type = true>
49+
template <class U>
50+
requires std::is_convertible_v<U, Type>
5151
Description(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
5252

53-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
54-
bool>::type = true>
53+
template <class U>
54+
requires std::is_convertible_v<U, Type>
5555
Description(const Description<_description, U>& _field)
5656
: value_(_field.value()) {}
5757

5858
/// Assigns the underlying object to its default value.
59-
template <class U = Type,
60-
typename std::enable_if<std::is_default_constructible_v<U>,
61-
bool>::type = true>
59+
template <class U = Type>
60+
requires std::is_default_constructible_v<U>
6261
Description(const Default&) : value_(Type()) {}
6362

6463
~Description() = default;
@@ -88,29 +87,26 @@ struct Description {
8887
}
8988

9089
/// Assigns the underlying object.
91-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
92-
bool>::type = true>
90+
template <class U>
91+
requires std::is_convertible_v<U, Type>
9392
auto& operator=(const U& _value) {
9493
value_ = _value;
9594
return *this;
9695
}
9796

9897
/// Assigns the underlying object to its default value.
99-
template <class U = Type,
100-
typename std::enable_if<std::is_default_constructible_v<U>,
101-
bool>::type = true>
98+
template <class U = Type>
99+
requires std::is_default_constructible_v<U>
102100
auto& operator=(const Default&) {
103101
value_ = Type();
104102
return *this;
105103
}
106104

107105
/// Assigns the underlying object.
108-
Description& operator=(
109-
const Description& _field) = default;
106+
Description& operator=(const Description& _field) = default;
110107

111108
/// Assigns the underlying object.
112-
Description& operator=(
113-
Description&& _field) = default;
109+
Description& operator=(Description&& _field) = default;
114110

115111
/// Assigns the underlying object.
116112
template <class U>

include/rfl/Field.hpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,21 @@ struct Field {
3636
template <class U>
3737
Field(Field<_name, U>&& _field) : value_(_field.get()) {}
3838

39-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
40-
bool>::type = true>
39+
template <class U>
40+
requires std::is_convertible_v<U, Type>
4141
Field(const U& _value) : value_(_value) {}
4242

43-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
44-
bool>::type = true>
43+
template <class U>
44+
requires std::is_convertible_v<U, Type>
4545
Field(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
4646

47-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
48-
bool>::type = true>
47+
template <class U>
48+
requires std::is_convertible_v<U, Type>
4949
Field(const Field<_name, U>& _field) : value_(_field.value()) {}
5050

5151
/// Assigns the underlying object to its default value.
52-
template <class U = Type,
53-
typename std::enable_if<std::is_default_constructible_v<U>,
54-
bool>::type = true>
52+
template <class U = Type>
53+
requires std::is_default_constructible_v<U>
5554
Field(const Default&) : value_(Type()) {}
5655

5756
~Field() = default;
@@ -84,17 +83,16 @@ struct Field {
8483
}
8584

8685
/// Assigns the underlying object.
87-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
88-
bool>::type = true>
86+
template <class U>
87+
requires std::is_convertible_v<U, Type>
8988
auto& operator=(const U& _value) {
9089
value_ = _value;
9190
return *this;
9291
}
9392

9493
/// Assigns the underlying object to its default value.
95-
template <class U = Type,
96-
typename std::enable_if<std::is_default_constructible_v<U>,
97-
bool>::type = true>
94+
template <class U = Type>
95+
requires std::is_default_constructible_v<U>
9896
auto& operator=(const Default&) {
9997
value_ = Type();
10098
return *this;

include/rfl/Flatten.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ struct Flatten {
3131
template <class U>
3232
Flatten(Flatten<U>&& _f) : value_(_f.get()) {}
3333

34-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
35-
bool>::type = true>
34+
template <class U>
35+
requires std::is_convertible_v<U, Type>
3636
Flatten(const U& _value) : value_(_value) {}
3737

38-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
39-
bool>::type = true>
38+
template <class U>
39+
requires std::is_convertible_v<U, Type>
4040
Flatten(U&& _value) : value_(_value) {}
4141

4242
~Flatten() = default;
@@ -66,8 +66,8 @@ struct Flatten {
6666
}
6767

6868
/// Assigns the underlying object.
69-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
70-
bool>::type = true>
69+
template <class U>
70+
requires std::is_convertible_v<U, Type>
7171
Flatten& operator=(const U& _value) {
7272
value_ = _value;
7373
return *this;

include/rfl/Generic.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ class RFL_API Generic {
3838

3939
Generic(const ReflectionType& _value);
4040

41-
template <class T,
42-
typename std::enable_if<std::is_convertible_v<T, VariantType>,
43-
bool>::type = true>
41+
template <class T>
42+
requires std::is_convertible_v<T, VariantType>
4443
Generic(const T& _value) {
4544
value_ = _value;
4645
}
4746

48-
template <class T,
49-
typename std::enable_if<std::is_convertible_v<T, VariantType>,
50-
bool>::type = true>
47+
template <class T>
48+
requires std::is_convertible_v<T, VariantType>
5149
Generic(T&& _value) noexcept : value_(std::forward<T>(_value)) {}
5250

5351
~Generic();
@@ -65,9 +63,8 @@ class RFL_API Generic {
6563
Generic& operator=(VariantType&& _value) noexcept;
6664

6765
/// Assigns the underlying object.
68-
template <class T,
69-
typename std::enable_if<std::is_convertible_v<T, VariantType>,
70-
bool>::type = true>
66+
template <class T>
67+
requires std::is_convertible_v<T, VariantType>
7168
auto& operator=(const T& _value) {
7269
using Type = std::remove_cvref_t<T>;
7370
if constexpr (std::is_same_v<Type, bool>) {

include/rfl/Hex.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace rfl {
1212

1313
/// Used to define a field in the NamedTuple.
1414
template <class T>
15-
requires std::is_integral_v<T>
15+
requires std::is_integral_v<T>
1616
struct Hex {
1717
/// The underlying type.
1818
using Type = T;
@@ -33,16 +33,16 @@ struct Hex {
3333
template <class U>
3434
Hex(Hex<U>&& _other) : value_(_other.get()) {}
3535

36-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
37-
bool>::type = true>
36+
template <class U>
37+
requires std::is_convertible_v<U, Type>
3838
Hex(const U& _value) : value_(_value) {}
3939

40-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
41-
bool>::type = true>
40+
template <class U>
41+
requires std::is_convertible_v<U, Type>
4242
Hex(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
4343

44-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
45-
bool>::type = true>
44+
template <class U>
45+
requires std::is_convertible_v<U, Type>
4646
Hex(const Hex<U>& _other) : value_(_other.value()) {}
4747

4848
Hex(const std::string& _str) {
@@ -67,8 +67,8 @@ struct Hex {
6767
}
6868

6969
/// Assigns the underlying object.
70-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
71-
bool>::type = true>
70+
template <class U>
71+
requires std::is_convertible_v<U, Type>
7272
auto& operator=(const U& _value) {
7373
value_ = _value;
7474
return *this;

include/rfl/Oct.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace rfl {
1313

1414
/// Used to define a field in the NamedTuple.
1515
template <class T>
16-
requires std::is_integral_v<T>
16+
requires std::is_integral_v<T>
1717
struct Oct {
1818
/// The underlying type.
1919
using Type = T;
@@ -34,16 +34,16 @@ struct Oct {
3434
template <class U>
3535
Oct(Oct<U>&& _other) : value_(_other.get()) {}
3636

37-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
38-
bool>::type = true>
37+
template <class U>
38+
requires std::is_convertible_v<U, Type>
3939
Oct(const U& _value) : value_(_value) {}
4040

41-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
42-
bool>::type = true>
41+
template <class U>
42+
requires std::is_convertible_v<U, Type>
4343
Oct(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
4444

45-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
46-
bool>::type = true>
45+
template <class U>
46+
requires std::is_convertible_v<U, Type>
4747
Oct(const Oct<U>& _other) : value_(_other.value()) {}
4848

4949
Oct(const std::string& _str) {
@@ -68,8 +68,8 @@ struct Oct {
6868
}
6969

7070
/// Assigns the underlying object.
71-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
72-
bool>::type = true>
71+
template <class U>
72+
requires std::is_convertible_v<U, Type>
7373
auto& operator=(const U& _value) {
7474
value_ = _value;
7575
return *this;

0 commit comments

Comments
 (0)