Skip to content

Commit fa9d367

Browse files
committed
Update dbg_demo.cpp with recent changes from template.cpp
1 parent 520183d commit fa9d367

File tree

1 file changed

+5
-27
lines changed

1 file changed

+5
-27
lines changed

templates/dbg_demo.cpp

+5-27
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66
using namespace std;
77

88
#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-
219
template <typename, typename = void>
2210
constexpr bool is_iterable_v{};
2311

@@ -33,8 +21,7 @@ constexpr bool is_iterable_v<
3321
template <typename A, typename B>
3422
string to_string(pair<A, B> p);
3523

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);
3825

3926
string to_string(const string& s) {
4027
return '"' + s + '"';
@@ -108,19 +95,10 @@ string to_string(pair<A, B> p) {
10895
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
10996
}
11097

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;
124102
}
125103

126104

0 commit comments

Comments
 (0)