C++20 is a unique historic milestone: It's the first edition of Standard C++ that’s “D&E-complete,” with essentially all of the features Bjarne Stroustrup outlined in /The Design and Evolution of C++/ for C++’s evolution. That doesn’t mean evolution is done, however, and work continues on adding a few more important features in C++23 and beyond, including reflection and pattern matching.
In this talk, I’ll show the C++ pattern matching libraries and language proposals we’ve considered, and present my own contribution that builds on them. My paper has two major aims: (1) to make the syntax clean and regular, and avoid inventing a little sublanguage that works only inside “inspect”; and (2) to make it generalizable so we can use it consistently throughout the language, because matching a pattern is a broadly useful feature that ideally should not be limited to “inspect” only… for example, we would love to express patterns in “if” and “requires” conditions too.
I hope that the most important contribution is that, if we add pattern matching in a way that also provides general “match” and “extract” support throughout the language in the form of generalized “is” constraints and “as” casts, the net result is that we can actually simplify C++… yes, even as we add new features and more expressive power. How can that be simpler? By letting programmers directly express their intent where they have to express it indirectly today, by making the language more regular with fewer special cases to learn, by unifying the syntax of existing standard library features that today have a gaggle of different and divergent styles (e.g., variant, optional), and by providing one general and expressive way to use patterns cleanly throughout C++.
PUBLICATION PERMISSIONS: CppCon Organizer provided Coding Tech with the permission to republish CppCon tech talks.
CREDITS: CppCon YouTube channel: https://www.youtube.com/channel/UCMlGfpWw-RUdWX_JbLCukXg