@@ -75,6 +75,23 @@ concept json_auto_map_like =
75
75
!json_auto_has_method<T> &&
76
76
std::is_same_v<typename T::key_type, JSON::String>;
77
77
78
+ // / @ingroup json
79
+ template <typename T>
80
+ concept json_auto_tuple_mono =
81
+ std::tuple_size_v<std::remove_cvref_t <std::tuple<T>>> == 1 ;
82
+
83
+ // We have to do this mess because MSVC seems confuses `std::pair`
84
+ // of 2 elements with this overload
85
+ // / @ingroup json
86
+ template <typename T>
87
+ concept json_auto_tuple_poly =
88
+ requires { typename std::tuple_size<std::remove_cvref_t <T>>::type; } &&
89
+ (std::tuple_size_v<std::remove_cvref_t <T>> >= 2 ) &&
90
+ (!std::is_base_of_v<
91
+ std::pair<std::tuple_element_t <0 , std::remove_cvref_t <T>>,
92
+ std::tuple_element_t <1 , std::remove_cvref_t <T>>>,
93
+ std::remove_cvref_t <T>>);
94
+
78
95
// / @ingroup json
79
96
// / If the value has a `.to_json()` method, always prefer that
80
97
template <typename T>
@@ -216,27 +233,16 @@ auto to_json(const std::pair<L, R> &value) -> JSON {
216
233
217
234
// Handle 1-element tuples
218
235
// / @ingroup json
219
- template <typename T>
220
- requires (std::tuple_size_v<std::remove_cvref_t <std::tuple<T>>> == 1 )
236
+ template <json_auto_tuple_mono T>
221
237
auto to_json (const std::tuple<T> &value) -> JSON {
222
238
auto tuple = JSON::make_array ();
223
239
std::apply ([&](const T &element) { tuple.push_back (to_json (element)); },
224
240
value);
225
241
return tuple;
226
242
}
227
243
228
- // We have to do this mess because MSVC seems confuses `std::pair`
229
- // of 2 elements with this overload
230
244
// / @ingroup json
231
- template <typename TupleT>
232
- requires (requires {
233
- typename std::tuple_size<std::remove_cvref_t <TupleT>>::type;
234
- } && (std::tuple_size_v<std::remove_cvref_t <TupleT>> >= 2 ) &&
235
- (!std::is_base_of_v<
236
- std::pair<std::tuple_element_t <0 , std::remove_cvref_t <TupleT>>,
237
- std::tuple_element_t <1 , std::remove_cvref_t <TupleT>>>,
238
- std::remove_cvref_t <TupleT>>))
239
- auto to_json (const TupleT &value) -> JSON {
245
+ template <json_auto_tuple_poly T> auto to_json (const T &value) -> JSON {
240
246
auto tuple = JSON::make_array ();
241
247
std::apply (
242
248
[&tuple](const auto &...elements ) {
0 commit comments