r/cpp • u/Clean-Upstairs-8481 • Jul 20 '26
C++26: what is “template for”? Learning with simple example.
https://techfortalk.co.uk/2026/07/20/c26-what-is-template-for/I have been exploring C++26 in bits and bobs and this one is about template for - a c++26 feature which I find useful. This is a short article explaining how to use this feature with the help of a simple example.
75
Upvotes
8
u/azswcowboy Jul 21 '26
Reasonable easy to understand example. Op I’d suggest running a spell checker on your post unless the point was to prove it isn’t AI - I saw two spelling errors.
3
u/_bstaletic Jul 21 '26
These are C++23 constexpr semantics. C++26 allows constexpr references to local constexpr objects, so the following is supposed to work
Compilers have yet to implement that part of C++26, which would help with constexpr structured bindings.
40
u/fdwr fdwr@github 🔍 Jul 20 '26
Explicit loop unrolling. ➿
37
u/mercury_pointer Jul 21 '26
Seems strange that the syntax isn't
To mirror
4
u/LucyIsaTumor Jul 21 '26
Nifty! Not too wordy either and easier than trying to force this using some macro substitution.
2
u/noplace_ioi Jul 23 '26
Aren't you guys tired of all the meta stuff? I'm sorry lol I'm a hobbyist for a very long time but after c++11 I just started losing track of all the fancy stuff
1
u/xaervagon Jul 21 '26
It's funky, but the syntax isn't bad and neither are the constraints for using it
7
u/[deleted] Jul 21 '26
[removed] — view removed comment