@@ -884,9 +884,25 @@ concept ObjectBaseType = std::is_base_of_v<Object, Type>;
884
884
template <typename Type>
885
885
concept ObjectDerivedType = ObjectBaseType<Type> && !ObjectType<Type>;
886
886
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>);
890
906
891
907
// Convert the result of a resolver function with chained type modifiers that add nullable or
892
908
// list wrappers. This is the inverse of ModifiedArgument for output types instead of input types.
@@ -897,17 +913,15 @@ struct ModifiedResult
897
913
template <typename U, TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
898
914
struct ResultTraits
899
915
{
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>,
904
918
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> ,
906
920
std::vector<typename ResultTraits<U, Other...>::type>,
907
921
typename std::conditional_t <ObjectBaseType<U>, std::shared_ptr<U>, U>>>;
908
922
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>>;
911
925
};
912
926
913
927
template <typename U>
@@ -926,8 +940,8 @@ struct ModifiedResult
926
940
// Peel off the none modifier. If it's included, it should always be last in the list.
927
941
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
928
942
[[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...>
931
945
{
932
946
// Call through to the Object specialization with a static_pointer_cast for subclasses of
933
947
// Object.
@@ -947,8 +961,8 @@ struct ModifiedResult
947
961
// Peel off the none modifier. If it's included, it should always be last in the list.
948
962
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
949
963
[[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...>
952
966
{
953
967
static_assert (sizeof ...(Other) == 0 , " None modifier should always be last" );
954
968
@@ -960,9 +974,7 @@ struct ModifiedResult
960
974
template <TypeModifier Modifier, TypeModifier... Other>
961
975
[[nodiscard]] static inline AwaitableResolver convert (
962
976
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...>
966
978
{
967
979
co_await params.launch ;
968
980
@@ -983,9 +995,7 @@ struct ModifiedResult
983
995
template <TypeModifier Modifier, TypeModifier... Other>
984
996
[[nodiscard]] static inline AwaitableResolver convert (
985
997
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...>
989
999
{
990
1000
static_assert (std::is_same_v<std::optional<typename ResultTraits<Type, Other...>::type>,
991
1001
typename ResultTraits<Type, Modifier, Other...>::type>,
@@ -1137,7 +1147,8 @@ struct ModifiedResult
1137
1147
1138
1148
// Peel off nullable modifiers.
1139
1149
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>
1141
1152
{
1142
1153
if (value.type () != response::Type::Null)
1143
1154
{
0 commit comments