@@ -79,9 +79,11 @@ enum class TypeModifier
7979 List,
8080};
8181
82- struct DisableNone {};
83- struct DisableNullable {};
84- struct DisableList {};
82+ template <TypeModifier _Modifier>
83+ struct DisabledModifier
84+ {
85+ DisabledModifier () = delete ;
86+ };
8587
8688// Extract individual arguments with chained type modifiers which add nullable or list wrappers.
8789// If the argument is not optional, use require and let it throw a schema_exception when the
@@ -100,7 +102,7 @@ struct ModifiedArgument
100102 >::type;
101103
102104 // 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,
104106 const web::json::object& arguments)
105107 {
106108 static_assert (TypeModifier::None == _Modifier, " this is the empty version" );
@@ -111,7 +113,7 @@ struct ModifiedArgument
111113 }
112114
113115 // 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,
115117 const web::json::object& arguments)
116118 {
117119 static_assert (TypeModifier::Nullable == _Modifier, " this is the nullable version" );
@@ -140,7 +142,7 @@ struct ModifiedArgument
140142 }
141143
142144 // 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,
144146 const web::json::object& arguments)
145147 {
146148 static_assert (TypeModifier::List == _Modifier, " this is the list version" );
@@ -259,7 +261,10 @@ class Object : public std::enable_shared_from_this<Object>
259261
260262using TypeMap = std::unordered_map<std::string, std::shared_ptr<Object>>;
261263
262- struct DisableNullableSharedPtr {};
264+ struct DisabledNullableSharedPtr
265+ {
266+ DisabledNullableSharedPtr () = delete ;
267+ };
263268
264269// Convert the result of a resolver function with chained type modifiers that add nullable or
265270// list wrappers. This is the inverse of ModifiedArgument for output types instead of input types.
@@ -282,7 +287,7 @@ struct ModifiedResult
282287 >::type;
283288
284289 // 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,
286291 ResolverParams&& params)
287292 {
288293 static_assert (TypeModifier::None == _Modifier, " this is the empty version" );
@@ -294,7 +299,7 @@ struct ModifiedResult
294299
295300 // Peel off nullable modifiers for std::shared_ptr<Object>.
296301 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,
298303 ResolverParams&& params)
299304 {
300305 static_assert (TypeModifier::Nullable == _Modifier, " this is the nullable version" );
@@ -310,7 +315,7 @@ struct ModifiedResult
310315
311316 // Peel off nullable modifiers for anything else, which should all be std::unique_ptr.
312317 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,
314319 ResolverParams&& params)
315320 {
316321 static_assert (TypeModifier::Nullable == _Modifier, " this is the nullable version" );
@@ -325,7 +330,7 @@ struct ModifiedResult
325330 }
326331
327332 // 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,
329334 ResolverParams&& params)
330335 {
331336 static_assert (TypeModifier::List == _Modifier, " this is the list version" );
@@ -352,16 +357,17 @@ struct ModifiedResult<_Type, TypeModifier::None>
352357
353358 // Convert a subclass of Object and call that specialization.
354359 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)
356361 {
362+ static_assert (!std::is_same<Object, _Type>::value && std::is_base_of<Object, _Type>::value, " should only be selected for subclasses of Object" );
357363 static_assert (std::is_same<std::shared_ptr<_Type>, type>::value, " this is the derived object type" );
358364
359365 return ModifiedResult<Object>::convert (std::static_pointer_cast<Object>(result), std::move (params));
360366 }
361367
362368 // Convert a single value of the specified type to JSON.
363369 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);
365371};
366372
367373// Convenient type aliases for testing, generated code won't actually use these. These are also
0 commit comments