6
6
using namespace std ;
7
7
8
8
#pragma region // setup for dbg() printouts
9
- template <typename , typename =void >
10
- constexpr bool is_tuplelike_v{};
11
-
12
- template <typename T>
13
- constexpr bool is_tuplelike_v<
14
- T,
15
- void_t <
16
- decltype (std::get<0 >(declval<T>())),
17
- decltype(std::tuple_size_v<T>)
18
- >
19
- > = true;
20
-
21
9
template <typename , typename = void >
22
10
constexpr bool is_iterable_v{};
23
11
@@ -33,8 +21,7 @@ constexpr bool is_iterable_v<
33
21
template <typename A, typename B>
34
22
string to_string (pair<A, B> p);
35
23
36
- template <typename X>
37
- typename enable_if<is_tuplelike_v<X>, string>::type to_string (X p);
24
+ template <class ...Ts> string to_string (const tuple<Ts...>& t);
38
25
39
26
string to_string (const string& s) {
40
27
return ' "' + s + ' "' ;
@@ -108,19 +95,10 @@ string to_string(pair<A, B> p) {
108
95
return " (" + to_string (p.first ) + " , " + to_string (p.second ) + " )" ;
109
96
}
110
97
111
- template <class T , size_t k>
112
- void to_string_tuplehelper (string& out, T& t) {
113
- out += " , " + to_string (get<k>(t));
114
- if constexpr (k < tuple_size_v<T> - 1 ) {
115
- to_string_tuplehelper<T, k+1 >(out, t);
116
- }
117
- }
118
- template <typename X>
119
- typename enable_if<is_tuplelike_v<X>, string>::type to_string (X p) {
120
- string out = " (" + to_string (get<0 >(p));
121
- to_string_tuplehelper<X, 1 >(out, p);
122
- out += " )" ;
123
- return out;
98
+ template <class ...Ts> string to_string (const tuple<Ts...>& t) {
99
+ string out = " (" ;
100
+ apply ([&](const Ts& ...args ) {((out += to_string (args) + " , " ), ...);}, t);
101
+ out.pop_back (); out.pop_back (); out.push_back (' )' ); return out;
124
102
}
125
103
126
104
0 commit comments