Skip to content

Commit f724528

Browse files
committed
Fix the shared_ptr/unique_ptr SFINAE logic
1 parent fec456b commit f724528

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

GraphQLService.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ struct ModifiedResult
262262
struct ResultTraits
263263
{
264264
using type = typename std::conditional<TypeModifier::Nullable == _Modifier,
265-
typename std::conditional<std::is_base_of<Object, _Type>::value
265+
typename std::conditional<std::is_base_of<Object, U>::value
266266
&& std::is_same<std::shared_ptr<U>, typename ResultTraits<U, _Other...>::type>::value,
267267
std::shared_ptr<U>,
268268
std::unique_ptr<typename ResultTraits<U, _Other...>::type>
@@ -307,14 +307,11 @@ struct ModifiedResult
307307
return convert(result, std::move(params));
308308
}
309309

310-
// Peel off nullable modifiers for std::shared_ptr<Object>.
310+
// Peel off final nullable modifiers for std::shared_ptr of Object and subclasses of Object.
311311
template <TypeModifier _Modifier, TypeModifier... _Other>
312-
static typename std::enable_if<TypeModifier::Nullable == _Modifier && std::is_same<std::shared_ptr<_Type>, typename ResultTraits<_Type, _Modifier, _Other...>::type>::value,
312+
static typename std::enable_if<TypeModifier::Nullable == _Modifier && std::is_same<std::shared_ptr<_Type>, typename ResultTraits<_Type, _Other...>::type>::value,
313313
web::json::value>::type convert(const typename ResultTraits<_Type, _Modifier, _Other...>::type& result, ResolverParams&& params)
314314
{
315-
static_assert(TypeModifier::Nullable == _Modifier, "this is the nullable version");
316-
static_assert(std::is_same<std::shared_ptr<_Type>, typename ResultTraits<_Type, _Modifier, _Other...>::type>::value, "this is the shared_ptr version");
317-
318315
if (!result)
319316
{
320317
return web::json::value::null();
@@ -325,11 +322,11 @@ struct ModifiedResult
325322

326323
// Peel off nullable modifiers for anything else, which should all be std::unique_ptr.
327324
template <TypeModifier _Modifier, TypeModifier... _Other>
328-
static typename std::enable_if<TypeModifier::Nullable == _Modifier && !std::is_same<std::shared_ptr<_Type>, typename ResultTraits<_Type, _Modifier, _Other...>::type>::value,
325+
static typename std::enable_if<TypeModifier::Nullable == _Modifier && !std::is_same<std::shared_ptr<_Type>, typename ResultTraits<_Type, _Other...>::type>::value,
329326
web::json::value>::type convert(const typename ResultTraits<_Type, _Modifier, _Other...>::type& result, ResolverParams&& params)
330327
{
331-
static_assert(TypeModifier::Nullable == _Modifier, "this is the nullable version");
332-
static_assert(!std::is_same<std::shared_ptr<_Type>, typename ResultTraits<_Type, _Modifier, _Other...>::type>::value, "this is the unique_ptr version or a subclass of Object");
328+
static_assert(std::is_same<std::unique_ptr<typename ResultTraits<_Type, _Other...>::type>, typename ResultTraits<_Type, _Modifier, _Other...>::type>::value,
329+
"this is the unique_ptr version");
333330

334331
if (!result)
335332
{
@@ -344,8 +341,6 @@ struct ModifiedResult
344341
static typename std::enable_if<TypeModifier::List == _Modifier,
345342
web::json::value>::type convert(const typename ResultTraits<_Type, _Modifier, _Other...>::type& result, ResolverParams&& params)
346343
{
347-
static_assert(TypeModifier::List == _Modifier, "this is the list version");
348-
349344
auto value = web::json::value::array(result.size());
350345

351346
std::transform(result.cbegin(), result.cend(), value.as_array().begin(),

0 commit comments

Comments
 (0)