@@ -83,6 +83,14 @@ concept InputVariableClass = std::is_class_v<Type> && !ScalarVariableClass<Type>
83
83
template <TypeModifier... Other>
84
84
concept OnlyNoneModifiers = (... && (Other == TypeModifier::None));
85
85
86
+ // Test if the next modifier is Nullable.
87
+ template <TypeModifier Modifier>
88
+ concept NullableModifier = Modifier == TypeModifier::Nullable;
89
+
90
+ // Test if the next modifier is List.
91
+ template <TypeModifier Modifier>
92
+ concept ListModifier = Modifier == TypeModifier::List;
93
+
86
94
// Special-case an innermost nullable INPUT_OBJECT type.
87
95
template <typename Type, TypeModifier... Other>
88
96
concept InputVariableUniquePtr = InputVariableClass<Type> && OnlyNoneModifiers<Other...>;
@@ -114,20 +122,18 @@ struct ModifiedVariable
114
122
115
123
// Peel off the none modifier. If it's included, it should always be last in the list.
116
124
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
117
- [[nodiscard]] static inline
118
- typename std::enable_if_t <TypeModifier::None == Modifier && sizeof ...(Other) == 0 ,
119
- response::Value>
120
- serialize (Type&& value)
125
+ [[nodiscard]] static inline response::Value serialize (
126
+ Type&& value) requires OnlyNoneModifiers<Modifier, Other...>
121
127
{
122
128
// Just call through to the non-template method without the modifiers.
123
129
return serialize (std::move (value));
124
130
}
125
131
126
132
// Peel off nullable modifiers.
127
133
template <TypeModifier Modifier, TypeModifier... Other>
128
- [[nodiscard]] static inline
129
- typename std:: enable_if_t <TypeModifier::Nullable == Modifier, response::Value>
130
- serialize ( typename VariableTraits<Type, Modifier, Other...>::type&& nullableValue)
134
+ [[nodiscard]] static inline response::Value serialize (
135
+ typename VariableTraits<Type, Modifier, Other...>::type&& nullableValue) requires
136
+ NullableModifier< Modifier>
131
137
{
132
138
response::Value result;
133
139
@@ -142,9 +148,9 @@ struct ModifiedVariable
142
148
143
149
// Peel off list modifiers.
144
150
template <TypeModifier Modifier, TypeModifier... Other>
145
- [[nodiscard]] static inline
146
- typename std:: enable_if_t <TypeModifier::List == Modifier, response::Value>
147
- serialize ( typename VariableTraits<Type, Modifier, Other...>::type&& listValue)
151
+ [[nodiscard]] static inline response::Value serialize (
152
+ typename VariableTraits<Type, Modifier, Other...>::type&& listValue) requires
153
+ ListModifier< Modifier>
148
154
{
149
155
response::Value result { response::Type::List };
150
156
@@ -159,19 +165,18 @@ struct ModifiedVariable
159
165
160
166
// Peel off the none modifier. If it's included, it should always be last in the list.
161
167
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
162
- [[nodiscard]] static inline
163
- typename std::enable_if_t <TypeModifier::None == Modifier && sizeof ...(Other) == 0 , Type>
164
- duplicate (const Type& value)
168
+ [[nodiscard]] static inline Type duplicate (
169
+ const Type& value) requires OnlyNoneModifiers<Modifier, Other...>
165
170
{
166
171
// Just copy the value.
167
172
return Type { value };
168
173
}
169
174
170
175
// Peel off nullable modifiers.
171
176
template <TypeModifier Modifier, TypeModifier... Other>
172
- [[nodiscard]] static inline typename std:: enable_if_t <TypeModifier::Nullable == Modifier,
173
- typename VariableTraits<Type, Modifier, Other...>::type>
174
- duplicate ( const typename VariableTraits<Type, Modifier, Other...>::type& nullableValue)
177
+ [[nodiscard]] static inline typename VariableTraits<Type, Modifier, Other...>::type duplicate (
178
+ const typename VariableTraits<Type, Modifier, Other...>::type& nullableValue) requires
179
+ NullableModifier< Modifier>
175
180
{
176
181
typename VariableTraits<Type, Modifier, Other...>::type result {};
177
182
@@ -193,9 +198,9 @@ struct ModifiedVariable
193
198
194
199
// Peel off list modifiers.
195
200
template <TypeModifier Modifier, TypeModifier... Other>
196
- [[nodiscard]] static inline typename std:: enable_if_t <TypeModifier::List == Modifier,
197
- typename VariableTraits<Type, Modifier, Other...>::type>
198
- duplicate ( const typename VariableTraits<Type, Modifier, Other...>::type& listValue)
201
+ [[nodiscard]] static inline typename VariableTraits<Type, Modifier, Other...>::type duplicate (
202
+ const typename VariableTraits<Type, Modifier, Other...>::type& listValue) requires
203
+ ListModifier< Modifier>
199
204
{
200
205
typename VariableTraits<Type, Modifier, Other...>::type result (listValue.size ());
201
206
@@ -259,18 +264,16 @@ struct ModifiedResponse
259
264
260
265
// Peel off the none modifier. If it's included, it should always be last in the list.
261
266
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
262
- [[nodiscard]] static inline
263
- typename std::enable_if_t <TypeModifier::None == Modifier && sizeof ...(Other) == 0 , Type>
264
- parse (response::Value&& response)
267
+ [[nodiscard]] static inline Type parse (
268
+ response::Value&& response) requires OnlyNoneModifiers<Modifier, Other...>
265
269
{
266
270
return parse (std::move (response));
267
271
}
268
272
269
273
// Peel off nullable modifiers.
270
274
template <TypeModifier Modifier, TypeModifier... Other>
271
- [[nodiscard]] static inline typename std::enable_if_t <TypeModifier::Nullable == Modifier,
272
- std::optional<typename ResponseTraits<Type, Other...>::type>>
273
- parse (response::Value&& response)
275
+ [[nodiscard]] static inline std::optional<typename ResponseTraits<Type, Other...>::type> parse (
276
+ response::Value&& response) requires NullableModifier<Modifier>
274
277
{
275
278
if (response.type () == response::Type::Null)
276
279
{
@@ -283,9 +286,8 @@ struct ModifiedResponse
283
286
284
287
// Peel off list modifiers.
285
288
template <TypeModifier Modifier, TypeModifier... Other>
286
- [[nodiscard]] static inline typename std::enable_if_t <TypeModifier::List == Modifier,
287
- std::vector<typename ResponseTraits<Type, Other...>::type>>
288
- parse (response::Value&& response)
289
+ [[nodiscard]] static inline std::vector<typename ResponseTraits<Type, Other...>::type> parse (
290
+ response::Value&& response) requires ListModifier<Modifier>
289
291
{
290
292
std::vector<typename ResponseTraits<Type, Other...>::type> result;
291
293
0 commit comments