File tree 4 files changed +34
-10
lines changed
4 files changed +34
-10
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,17 @@ class basic_array
74
74
{
75
75
}
76
76
77
+ template <typename ... elem_ts>
78
+ basic_array (const std::tuple<elem_ts...>& tup)
79
+ {
80
+ foreach_tuple (tup, std::make_index_sequence<std::tuple_size_v<std::tuple<elem_ts...>>>());
81
+ }
82
+ template <typename first_t , typename second_t >
83
+ basic_array (std::pair<first_t , second_t > pair)
84
+ : _array_data({ std::move (pair.first ), std::move (pair.second ) })
85
+ {
86
+ }
87
+
77
88
~basic_array () noexcept = default ;
78
89
79
90
bool empty () const noexcept { return _array_data.empty (); }
@@ -238,6 +249,12 @@ class basic_array
238
249
template <size_t index, typename tuple_t >
239
250
void set_tuple (tuple_t & tup) const ;
240
251
252
+ template <typename Tuple, std::size_t ... Is>
253
+ void foreach_tuple (const Tuple& t, std::index_sequence<Is...>)
254
+ {
255
+ (_array_data.emplace_back (std::get<Is>(t)), ...);
256
+ }
257
+
241
258
string_t format (size_t indent, size_t indent_times) const ;
242
259
243
260
private:
Original file line number Diff line number Diff line change @@ -84,11 +84,6 @@ constexpr bool is_collection = false;
84
84
template <typename T>
85
85
constexpr bool is_collection<T> = is_container<T> && !is_map<T> && !is_fixed_array<T>;
86
86
87
- template <typename T, template <typename ...> typename Ref, typename = void >
88
- constexpr bool is_specialization = false ;
89
- template <template <typename ...> typename T, template <typename ...> typename Ref, typename ... Args>
90
- constexpr bool is_specialization<T<Args...>, Ref> = std::is_same_v<T<Args...>, Ref<Args...>>;
91
-
92
87
template <typename T>
93
88
class has_to_json_in_member
94
89
{
Original file line number Diff line number Diff line change @@ -122,11 +122,15 @@ class basic_value
122
122
{
123
123
}
124
124
125
- template <
126
- typename tuple_t ,
127
- std::enable_if_t <_utils::is_specialization<tuple_t , std::tuple>, bool > = true >
128
- basic_value (tuple_t && tup)
129
- : basic_value(basic_array<string_t >(std::forward<tuple_t >(tup)))
125
+ template <typename ... elem_ts>
126
+ basic_value (std::tuple<elem_ts...>&& tup)
127
+ : basic_value(basic_array<string_t >(std::forward<std::tuple<elem_ts...>>(tup)))
128
+ {
129
+ }
130
+
131
+ template <typename elem1_t , typename elem2_t >
132
+ basic_value (std::pair<elem1_t , elem2_t >&& pair)
133
+ : basic_value(basic_array<string_t >(std::pair<elem1_t , elem2_t >(pair)))
130
134
{
131
135
}
132
136
Original file line number Diff line number Diff line change @@ -364,6 +364,14 @@ bool jsonizing()
364
364
auto t3 = std::tuple<int , std::string>(tuple_val);
365
365
auto p3 = std::tuple<int , std::string>(tuple_val);
366
366
367
+ auto new_tuple_arr = (json::array)t;
368
+ auto new_tuple_val = (json::value)t;
369
+ new_tuple_val.as <std::tuple<int , std::string>>();
370
+ new_tuple_val.as <std::pair<int , std::string>>();
371
+
372
+ auto new_pair_arr = (json::array)p;
373
+ auto new_pair_val = (json::value)p;
374
+
367
375
return true ;
368
376
}
369
377
You can’t perform that action at this time.
0 commit comments