Suppose that you want to write a C++ that prints a series of values, but also their type.

E.g., given

print_all(1.2, "abc", 3, std::vector<int>({2,3}));

You want...

double = 1.2
const char* = abc
int = 3
std::vector<int> = [2, 3]

You can do it in C++26 with little code.

1. Use 'templattime iteration.

2. Call display_string_of on the reflection of the types. (Don't forget the rabbit ears ^^)
22
12
154
11,316
Replying to @lemire
@lemire Lo bueno es que sale de reflection nativa, imprimes el tipo sin macros ni RTTI y te funciona con cualquier tipo propio.

Aug 18, 2026 · 5:18 PM UTC

0
0
0
385
RepliesRelevant