@@ -70,19 +70,23 @@ enum class [[nodiscard]] TypeModifier {
7070 List,
7171};
7272
73- // Specialized to return true for all INPUT_OBJECT types .
73+ // These types are used as scalar variables even though they are represented with a class .
7474template <typename Type>
75- [[nodiscard]] constexpr bool isInputType () noexcept
76- {
77- return false ;
78- }
75+ concept ScalarVariableClass = std::is_same_v<Type, std::string> || std::is_same_v<Type,
76+ response::IdType> || std::is_same_v<Type, response::Value>;
7977
80- // Special-case an innermost nullable INPUT_OBJECT type.
78+ // Any non-scalar class used in a variable is a generated INPUT_OBJECT type.
79+ template <typename Type>
80+ concept InputVariableClass = std::is_class_v<Type> && !ScalarVariableClass<Type>;
81+
82+ // Test if there are any non-None modifiers left.
8183template <TypeModifier... Other>
82- [[nodiscard]] constexpr bool onlyNoneModifiers () noexcept
83- {
84- return (... && (Other == TypeModifier::None));
85- }
84+ concept OnlyNoneModifiers = (... && (Other == TypeModifier::None));
85+
86+ // Special-case an innermost nullable INPUT_OBJECT type.
87+ template <typename Type, TypeModifier... Other>
88+ concept InputVariableUniquePtr = InputVariableClass<Type> && OnlyNoneModifiers<Other...>;
89+
8690
8791// Serialize variable input values with chained type modifiers which add nullable or list wrappers.
8892template <typename Type>
@@ -94,8 +98,8 @@ struct ModifiedVariable
9498 {
9599 // Peel off modifiers until we get to the underlying type.
96100 using type = typename std::conditional_t <TypeModifier::Nullable == Modifier,
97- typename std::conditional_t <isInputType<U>() && onlyNoneModifiers< Other...>() ,
98- std::unique_ptr<U>, std:: optional<typename VariableTraits<U, Other...>::type>>,
101+ typename std::conditional_t <InputVariableUniquePtr<U, Other...>, std::unique_ptr<U> ,
102+ std::optional<typename VariableTraits<U, Other...>::type>>,
99103 typename std::conditional_t <TypeModifier::List == Modifier,
100104 std::vector<typename VariableTraits<U, Other...>::type>, U>>;
101105 };
@@ -173,7 +177,7 @@ struct ModifiedVariable
173177
174178 if (nullableValue)
175179 {
176- if constexpr (isInputType <Type>() && onlyNoneModifiers< Other...>() )
180+ if constexpr (InputVariableUniquePtr <Type, Other...>)
177181 {
178182 // Special case duplicating the std::unique_ptr.
179183 result = std::make_unique<Type>(Type { *nullableValue });
0 commit comments