@@ -79,9 +79,11 @@ enum class TypeModifier
79
79
List,
80
80
};
81
81
82
- struct DisableNone {};
83
- struct DisableNullable {};
84
- struct DisableList {};
82
+ template <TypeModifier _Modifier>
83
+ struct DisabledModifier
84
+ {
85
+ DisabledModifier () = delete ;
86
+ };
85
87
86
88
// Extract individual arguments with chained type modifiers which add nullable or list wrappers.
87
89
// If the argument is not optional, use require and let it throw a schema_exception when the
@@ -100,7 +102,7 @@ struct ModifiedArgument
100
102
>::type;
101
103
102
104
// Peel off the none modifier. If it's included, it should always be last in the list.
103
- static type require (const typename std::conditional<TypeModifier::None == _Modifier, std::string, DisableNone >::type& name,
105
+ static type require (const typename std::conditional<TypeModifier::None == _Modifier, std::string, DisabledModifier<TypeModifier::None> >::type& name,
104
106
const web::json::object& arguments)
105
107
{
106
108
static_assert (TypeModifier::None == _Modifier, " this is the empty version" );
@@ -111,7 +113,7 @@ struct ModifiedArgument
111
113
}
112
114
113
115
// Peel off nullable modifiers.
114
- static type require (const typename std::conditional<TypeModifier::Nullable == _Modifier, std::string, DisableNullable >::type& name,
116
+ static type require (const typename std::conditional<TypeModifier::Nullable == _Modifier, std::string, DisabledModifier<TypeModifier::Nullable> >::type& name,
115
117
const web::json::object& arguments)
116
118
{
117
119
static_assert (TypeModifier::Nullable == _Modifier, " this is the nullable version" );
@@ -140,7 +142,7 @@ struct ModifiedArgument
140
142
}
141
143
142
144
// Peel off list modifiers.
143
- static type require (const typename std::conditional<TypeModifier::List == _Modifier, std::string, DisableList >::type& name,
145
+ static type require (const typename std::conditional<TypeModifier::List == _Modifier, std::string, DisabledModifier<TypeModifier::List> >::type& name,
144
146
const web::json::object& arguments)
145
147
{
146
148
static_assert (TypeModifier::List == _Modifier, " this is the list version" );
@@ -259,7 +261,10 @@ class Object : public std::enable_shared_from_this<Object>
259
261
260
262
using TypeMap = std::unordered_map<std::string, std::shared_ptr<Object>>;
261
263
262
- struct DisableNullableSharedPtr {};
264
+ struct DisabledNullableSharedPtr
265
+ {
266
+ DisabledNullableSharedPtr () = delete ;
267
+ };
263
268
264
269
// Convert the result of a resolver function with chained type modifiers that add nullable or
265
270
// list wrappers. This is the inverse of ModifiedArgument for output types instead of input types.
@@ -282,7 +287,7 @@ struct ModifiedResult
282
287
>::type;
283
288
284
289
// Peel off the none modifier. If it's included, it should always be last in the list.
285
- static web::json::value convert (const typename std::conditional<TypeModifier::None == _Modifier, type, DisableNone >::type& result,
290
+ static web::json::value convert (const typename std::conditional<TypeModifier::None == _Modifier, type, DisabledModifier<TypeModifier::None> >::type& result,
286
291
ResolverParams&& params)
287
292
{
288
293
static_assert (TypeModifier::None == _Modifier, " this is the empty version" );
@@ -294,7 +299,7 @@ struct ModifiedResult
294
299
295
300
// Peel off nullable modifiers for std::shared_ptr<Object>.
296
301
static web::json::value convert (const typename std::conditional<TypeModifier::Nullable == _Modifier
297
- && std::is_same<std::shared_ptr<_Type>, typename ModifiedResult<_Type, _Other...>::type>::value, type, DisableNullableSharedPtr >::type& result,
302
+ && std::is_same<std::shared_ptr<_Type>, typename ModifiedResult<_Type, _Other...>::type>::value, type, DisabledNullableSharedPtr >::type& result,
298
303
ResolverParams&& params)
299
304
{
300
305
static_assert (TypeModifier::Nullable == _Modifier, " this is the nullable version" );
@@ -310,7 +315,7 @@ struct ModifiedResult
310
315
311
316
// Peel off nullable modifiers for anything else, which should all be std::unique_ptr.
312
317
static web::json::value convert (const typename std::conditional<TypeModifier::Nullable == _Modifier
313
- && !std::is_same<std::shared_ptr<_Type>, typename ModifiedResult<_Type, _Other...>::type>::value, type, DisableNullable >::type& result,
318
+ && !std::is_same<std::shared_ptr<_Type>, typename ModifiedResult<_Type, _Other...>::type>::value, type, DisabledModifier<TypeModifier::Nullable> >::type& result,
314
319
ResolverParams&& params)
315
320
{
316
321
static_assert (TypeModifier::Nullable == _Modifier, " this is the nullable version" );
@@ -325,7 +330,7 @@ struct ModifiedResult
325
330
}
326
331
327
332
// Peel off list modifiers.
328
- static web::json::value convert (const typename std::conditional<TypeModifier::List == _Modifier, type, DisableList >::type& result,
333
+ static web::json::value convert (const typename std::conditional<TypeModifier::List == _Modifier, type, DisabledModifier<TypeModifier::List> >::type& result,
329
334
ResolverParams&& params)
330
335
{
331
336
static_assert (TypeModifier::List == _Modifier, " this is the list version" );
@@ -352,16 +357,17 @@ struct ModifiedResult<_Type, TypeModifier::None>
352
357
353
358
// Convert a subclass of Object and call that specialization.
354
359
static web::json::value convert (const typename std::conditional<!std::is_same<Object, _Type>::value && std::is_base_of<Object, _Type>::value,
355
- type, DisableNone >::type& result, ResolverParams&& params)
360
+ type, DisabledModifier<TypeModifier::None> >::type& result, ResolverParams&& params)
356
361
{
362
+ static_assert (!std::is_same<Object, _Type>::value && std::is_base_of<Object, _Type>::value, " should only be selected for subclasses of Object" );
357
363
static_assert (std::is_same<std::shared_ptr<_Type>, type>::value, " this is the derived object type" );
358
364
359
365
return ModifiedResult<Object>::convert (std::static_pointer_cast<Object>(result), std::move (params));
360
366
}
361
367
362
368
// Convert a single value of the specified type to JSON.
363
369
static web::json::value convert (const typename std::conditional<!std::is_same<Object, _Type>::value && std::is_base_of<Object, _Type>::value,
364
- DisableNone , type>::type& result, ResolverParams&& params);
370
+ DisabledModifier<TypeModifier::None> , type>::type& result, ResolverParams&& params);
365
371
};
366
372
367
373
// Convenient type aliases for testing, generated code won't actually use these. These are also
0 commit comments