@@ -37,6 +37,63 @@ using FloatType = double;
3737using ScalarType = Value;
3838using IdType = std::vector<uint8_t >;
3939
40+ template <typename ValueType>
41+ struct ValueTypeTraits
42+ {
43+ // Set by r-value reference, get by const reference, and release by value. The only types
44+ // that actually support all 3 methods are StringType and ScalarType, everything else
45+ // overrides some subset of these types with a template specialization.
46+ using set_type = ValueType &&;
47+ using get_type = const ValueType &;
48+ using release_type = ValueType;
49+ };
50+
51+ template <>
52+ struct ValueTypeTraits <MapType>
53+ {
54+ // Get by const reference and release by value.
55+ using get_type = const MapType &;
56+ using release_type = MapType;
57+ };
58+
59+ template <>
60+ struct ValueTypeTraits <ListType>
61+ {
62+ // Get by const reference and release by value.
63+ using get_type = const ListType &;
64+ using release_type = ListType;
65+ };
66+
67+ template <>
68+ struct ValueTypeTraits <BooleanType>
69+ {
70+ // Set and get by value.
71+ using set_type = BooleanType;
72+ using get_type = BooleanType;
73+ };
74+
75+ template <>
76+ struct ValueTypeTraits <IntType>
77+ {
78+ // Set and get by value.
79+ using set_type = IntType;
80+ using get_type = IntType;
81+ };
82+
83+ template <>
84+ struct ValueTypeTraits <FloatType>
85+ {
86+ // Set and get by value.
87+ using set_type = FloatType;
88+ using get_type = FloatType;
89+ };
90+
91+ template <>
92+ struct ValueTypeTraits <IdType>
93+ {
94+ // ID values are represented as a String, there's no separate handling of this type.
95+ };
96+
4097struct TypedData ;
4198
4299// Represent a discriminated union of GraphQL response value types.
@@ -86,15 +143,15 @@ struct Value
86143
87144 // Specialized for all single-value Types.
88145 template <typename ValueType>
89- void set (ValueType&& value);
146+ void set (typename ValueTypeTraits< ValueType>::set_type value);
90147
91148 // Specialized for all Types.
92149 template <typename ValueType>
93- ValueType get () const ;
150+ typename ValueTypeTraits< ValueType>::get_type get () const ;
94151
95152 // Specialized for all Types which allocate extra memory.
96153 template <typename ValueType>
97- ValueType release ();
154+ typename ValueTypeTraits< ValueType>::release_type release ();
98155
99156private:
100157 const Type _type;
0 commit comments