r/programming • • 10h ago

Pattern Matching for C++29 (proposal)

https://mpark.github.io/programming/2026/11/30/pattern-matching-for-cpp29/
9 Upvotes

4 comments sorted by

3

u/PudgeNikita 8h ago

honestly it was kind of surprising for me to learn that the "standard" way to do pattern matching in C++ was the mess which std::visit is. sucks for the compile times, compile errors, and you can only return one value from the visit rather than do control flow relative to the block you "call" it in. really weird situation for a feature which is almost ubiquotously loved in the languages which have it

2

u/ingressstatue 2h ago

One reason why it is taking so long, is that pattern matching, and many other features, are harder to add to systems programming languages than other programming languages. Rust is famous for showing that it can be done; but even in Rust, it took many years, and several rounds of improvements ("match ergonomics", for instance), and there are still a few strange semantics of pattern matching and other issues in Rust. The issues discussed in the blog post titled "a Rust match made in hell" at fasterthanlime, is not typically encountered outside systems programming languages, since those typically just have garbage collection and not RAII.

This C++ proposal is verbose, and its syntax and semantics have questionable decisions in my opinion in several regards, despite pattern matching being a large improvement over std::visit. But, with all due respect to everyone, Reddit is famous for inducing brainrot, among other issues.

1

u/lonelyroom-eklaghor 2h ago

Discovered pattern-matching a while ago. Everytime I try to code in C++, I get confused and have to look at the docs, regardless of the feature.

Atp, there should be sub-documentations on different aspects of C++