r/cpp • u/adityazero • Sep 20 '26
CppCon At cppcon WG21 had a whiteboard asking attendees what they would like to have in C++29
some of the ones I remember was:
- contracts
- profiles
- delete moar stuff
I'm curious what folks here expect. Also if someone remembers rest of the list, that'd be great.
57
Upvotes
View all comments
Show parent comment
3
u/ts826848 Sep 20 '26
Oh, I see what you mean. I'm used to the
overloaded {}method of writing visitors I admittedly forgot you can also useif constexpr.That being said, I don't think the pattern matching you describe is quite comparable? For instance, "real" pattern matching can match runtime values, while
if constexprcan't. Deconstructing nested types/values is another thing that pattern matching makes significantly more ergonomic thanstd::visit. Pattern matching also handles variants with multiples of the same type quite well, though I want to say that's in no small part due to languages with pattern matching also tending to have named variants and anonymous tuples, both of which C++ lacks.Maybe an example would work better? One interesting example that has stuck with me is tree manipulations. Consider this OCaml tree definition:
Which I think is approximately this C++:
Given an unbalanced subtree after an insertion, where B/R are colors, x/y/z are values, and a/b/c/d are other
rbtreeinstances:You want this:
OCaml lets you rebalance the subtree quite neatly using pattern matching:
(There's more work to be done to finish the insertion, but that's beyond the scope of this example)
How would you express the same operation in current C++?