Pattern matching proposal P2688R6 for C++29 gets a design update
The author gives an update on the pattern matching proposal P2688R6 for C++29. Their example shows a long std::visit call with if constexpr branches replaced by a match expression with three case lines. At the Búzios meeting, EWG[1] took a poll and reached consensus that it "encourages more work in direction of P2688R6". The author plans to bring wording to the Istanbul meeting in March 2027.
Compared with the R5 version, R6 keeps pattern composition but uses existing declaration syntax to introduce names instead of let, and replaces infix match with a prefix match written as match (x) { ... }. It also adds exhaustiveness checking[2], so omitting one enumerator of an enum in a match expression is ill-formed. The examples cover value, declaration, wildcard pattern[3] and or-patterns, decomposition patterns[4] for std::pair, if guards, and alternative patterns for std::optional.
The earlier R5 version did not gain consensus for C++26 at the Hagenberg meeting in February 2025, with the poll result 20/11/6/13/5. An implementation is available in a clang branch on Compiler Explorer.
Read the original mpark.github.ioDiscussion
Sources
-
Michael Park
Pattern Matching for C++29 (proposal)



