Skip to content

Commit 5f67ba5

Browse files
committed
Use a single concept per requires clause
1 parent 80435ed commit 5f67ba5

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

include/graphqlservice/GraphQLService.h

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,25 @@ concept ObjectBaseType = std::is_base_of_v<Object, Type>;
884884
template <typename Type>
885885
concept ObjectDerivedType = ObjectBaseType<Type> && !ObjectType<Type>;
886886

887-
// Test if ResultType is std::shared_ptr<Type>.
888-
template <typename ResultType, typename Type>
889-
concept ResultTypeSharedPtr = std::is_same_v<ResultType, std::shared_ptr<Type>>;
887+
// Test if this method should std::static_pointer_cast an ObjectDerivedType to
888+
// std::shared_ptr<const Object>.
889+
template <typename Type, TypeModifier Modifier, TypeModifier... Other>
890+
concept NoneObjectDerivedType = OnlyNoneModifiers<Modifier, Other...> && ObjectDerivedType<Type>;
891+
892+
// Test all other result types to see if they should call the specialized convert method without
893+
// template parameters.
894+
template <typename Type, TypeModifier Modifier, TypeModifier... Other>
895+
concept NoneScalarOrObjectType = OnlyNoneModifiers<Modifier, Other...> && !ObjectDerivedType<Type>;
896+
897+
// Test if this method should return a nullable std::shared_ptr<Type>
898+
template <typename Type, TypeModifier Modifier, TypeModifier... Other>
899+
concept NullableResultSharedPtr =
900+
NullableModifier<Modifier> && OnlyNoneModifiers<Other...> && ObjectBaseType<Type>;
901+
902+
// Test if this method should return a nullable std::optional<Type>
903+
template <typename Type, TypeModifier Modifier, TypeModifier... Other>
904+
concept NullableResultOptional =
905+
NullableModifier<Modifier> && !(OnlyNoneModifiers<Other...> && ObjectBaseType<Type>);
890906

891907
// Convert the result of a resolver function with chained type modifiers that add nullable or
892908
// list wrappers. This is the inverse of ModifiedArgument for output types instead of input types.
@@ -897,17 +913,15 @@ struct ModifiedResult
897913
template <typename U, TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
898914
struct ResultTraits
899915
{
900-
using type = typename std::conditional_t<TypeModifier::Nullable == Modifier,
901-
typename std::conditional_t<
902-
ObjectBaseType<
903-
U> && std::is_same_v<std::shared_ptr<U>, typename ResultTraits<U, Other...>::type>,
916+
using type = typename std::conditional_t<NullableModifier<Modifier>,
917+
typename std::conditional_t<OnlyNoneModifiers<Other...> && ObjectBaseType<U>,
904918
std::shared_ptr<U>, std::optional<typename ResultTraits<U, Other...>::type>>,
905-
typename std::conditional_t<TypeModifier::List == Modifier,
919+
typename std::conditional_t<ListModifier<Modifier>,
906920
std::vector<typename ResultTraits<U, Other...>::type>,
907921
typename std::conditional_t<ObjectBaseType<U>, std::shared_ptr<U>, U>>>;
908922

909-
using future_type = typename std::conditional_t<std::is_base_of_v<Object, U>,
910-
AwaitableObject<type>, AwaitableScalar<type>>;
923+
using future_type = typename std::conditional_t<ObjectBaseType<U>, AwaitableObject<type>,
924+
AwaitableScalar<type>>;
911925
};
912926

913927
template <typename U>
@@ -926,8 +940,8 @@ struct ModifiedResult
926940
// Peel off the none modifier. If it's included, it should always be last in the list.
927941
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
928942
[[nodiscard]] static inline AwaitableResolver convert(
929-
AwaitableObject<typename ResultTraits<Type>::type> result, ResolverParams params) requires
930-
OnlyNoneModifiers<Modifier, Other...> && ObjectDerivedType<Type>
943+
AwaitableObject<typename ResultTraits<Type>::type> result,
944+
ResolverParams params) requires NoneObjectDerivedType<Type, Modifier, Other...>
931945
{
932946
// Call through to the Object specialization with a static_pointer_cast for subclasses of
933947
// Object.
@@ -947,8 +961,8 @@ struct ModifiedResult
947961
// Peel off the none modifier. If it's included, it should always be last in the list.
948962
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
949963
[[nodiscard]] static inline AwaitableResolver convert(
950-
typename ResultTraits<Type>::future_type result, ResolverParams params) requires
951-
OnlyNoneModifiers<Modifier, Other...> && !ObjectDerivedType<Type>
964+
typename ResultTraits<Type>::future_type result,
965+
ResolverParams params) requires NoneScalarOrObjectType<Type, Modifier, Other...>
952966
{
953967
static_assert(sizeof...(Other) == 0, "None modifier should always be last");
954968

@@ -960,9 +974,7 @@ struct ModifiedResult
960974
template <TypeModifier Modifier, TypeModifier... Other>
961975
[[nodiscard]] static inline AwaitableResolver convert(
962976
typename ResultTraits<Type, Modifier, Other...>::future_type result,
963-
ResolverParams params) requires
964-
NullableModifier<Modifier> && ResultTypeSharedPtr<
965-
typename ResultTraits<Type, Other...>::type, Type>
977+
ResolverParams params) requires NullableResultSharedPtr<Type, Modifier, Other...>
966978
{
967979
co_await params.launch;
968980

@@ -983,9 +995,7 @@ struct ModifiedResult
983995
template <TypeModifier Modifier, TypeModifier... Other>
984996
[[nodiscard]] static inline AwaitableResolver convert(
985997
typename ResultTraits<Type, Modifier, Other...>::future_type result,
986-
ResolverParams params) requires
987-
NullableModifier<Modifier> && !ResultTypeSharedPtr<
988-
typename ResultTraits<Type, Other...>::type, Type>
998+
ResolverParams params) requires NullableResultOptional<Type, Modifier, Other...>
989999
{
9901000
static_assert(std::is_same_v<std::optional<typename ResultTraits<Type, Other...>::type>,
9911001
typename ResultTraits<Type, Modifier, Other...>::type>,
@@ -1137,7 +1147,8 @@ struct ModifiedResult
11371147

11381148
// Peel off nullable modifiers.
11391149
template <TypeModifier Modifier, TypeModifier... Other>
1140-
static inline void validateScalar(const response::Value& value) requires NullableModifier<Modifier>
1150+
static inline void validateScalar(
1151+
const response::Value& value) requires NullableModifier<Modifier>
11411152
{
11421153
if (value.type() != response::Type::Null)
11431154
{

0 commit comments

Comments
 (0)