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 ^^)

Aug 18, 2026 · 1:49 PM UTC

22
12
154
11,316
RepliesRelevant
Replying to @lemire
@lemire Works in Clang's reflection branch now!
godbolt.org/z/q6xP1sWbj
1
0
4
846
Replying to @AlaskaLawlor
@AlaskaLawlor It does!
0
0
3
766
Replying to @lemire
@lemire Awesome.
1
0
1
472
Replying to @KaiMeyer
@KaiMeyer glad you like it
0
0
1
432
Replying to @lemire
0
0
6
549
Replying to @lemire
@lemire i'm liking the ^^ syntax
0
0
3
247
Replying to @lemire
@lemire specialize `std::formatter&lt;std::meta::info&gt;` please I want to write:
`std::println("{}"sv, ^^int);`
0
0
4
278
Replying to @lemire
@lemire Man, that is ugly.
1
0
3
314
Replying to @lemire
@lemire You can do this in D with even less code, and a lot nicer. And we have been enjoying these abilities for years already.
1
0
2
392
Replying to @lemire
@lemire Very nice. Output:
0
0
1
288
Replying to @lemire
@lemire Reflection finally makes metaprogramming readable: types become data you can iterate at compile time — no tag dispatch, no recursive template instantiation, no SFINAE gymnastics. The rabbit ears are the only syntax left to explain.
0
0
1
299
Replying to @lemire
@lemire isn't this a bit "cheating"? you took everything by value, "abc" is const char[4], the others are prvalues too, but handy reflection indeed
1
0
1
578
Replying to @lemire
@lemire I think proper reflection has been long overdue in c++
0
0
0
21
Replying to @lemire
@lemire that part getting the display name is uglier than the C preprocessor solutions. using #t

a special achievement once again by the C++ low-standards committee
0
0
0
127
Replying to @lemire
@lemire Something about reading C++ code that makes my heart tingle
0
0
0
73
Replying to @lemire
@lemire probably the worst code that I seen in my life, and I am a C++ dev
1
0
0
227
Replying to @lemire
@lemire I have clearly missed a lot of great developments in C++.
0
0
0
58
Replying to @lemire
@lemire Make scoped namespacing cool again. Not everyone has developed "std::*" goggles, nor should they.
2
0
0
458
Replying to @lemire
@lemire Now, how many times is the vector copied?
0
0
0
140
Replying to @lemire
@lemire LOVELY
0
0
0
72
Replying to @lemire
@lemire #( 1.2 'abc' 3 #(2 3))
collect: [:obj | Transcript show: obj;
show: ' = ';
show: obj class; cr ].

1.2 = BoxedFloat64
abc = ByteString
3 = SmallInteger
#(2 3) = Array
0
0
0
397
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.
0
0
0
385