Pattern Matching: A Sneak Peek
summary
Proposal P1371 r1 brings pattern matching to C++ as a statement and expression form and shows concrete syntax and semantics: P1371 r1 documents inspect blocks, inspect expression with optional trailing return type, let vs case modes to disambiguate identifiers, wildcard and structured-binding patterns, designated-field patterns, alternative patterns for variants, reference patterns (!, ?) and a user-defined extractor pattern demonstrated with CTRE regex extraction. Examples show how nested std::variant + structured bindings collapse into compact matches and how this can eliminate repetitive dynamic_cast/std::visit boilerplate; the work is a draft proposal, not yet a language change.
AI-written summary · about
chapters (46)
- 0:00Introduction
- 1:42Motivations
- 8:47Composition
- 12:18What is Pattern Matching
- 12:53Point Example
- 13:36Color Coding
- 14:01Declarative
- 14:13A Closer Look
- 15:09Pattern Matching
- 17:30Patterns and Values
- 18:55Structure
- 20:05Expression Form
- 20:58Multiple Returns
- 21:48Pattern Guard
- 24:05Disclaimer
- 24:31Wildcard Pattern
- 25:27Identifier Pattern
- 26:01Wildcard
- 26:47Expression Pattern
- 27:43Static Concepts
- 28:01Two Modes
- 29:07Existing declarations
- 31:12Repeating the P
- 32:25Nesting into patterns
- 33:12Richards comment
- 33:28Structured bindings
- 35:02Alternative Pattern
- 36:06Constant Expression
- 36:32Auto
- 36:50Integral Concept
- 37:34Polymorphic Types
- 38:40Reference Pattern
- 41:25Star Questionmark
- 42:48Extractor
- 44:30CompilerTime Regular Expressions
- 44:49GTRe
- 46:17QuestionMark
- 47:05Extractors
- 48:24Syntax
- 50:18Visit
- 50:53Is Pattern Matching Required
- 52:30Double Underscore
- 54:13Expressions vs Statements
- 56:25wildcard patterns
- 57:11pattern matching in C
- 58:31best match vs first match
related talks
07mPattern Matching in C++14
58mThe Pattern Matching We Already Have
01h 07mDesign Patterns in Modern C++
39mAre You Structure Bindable? A Tour via Concepts, SFINAE & Herb Sutter's Pattern Matching
12mTraits Go Mainstream...
01h 40mDesign Patterns: Examples in C++
57mIntroduction to C++ Template Metaprogramming
01h 13mType safe C++ – LOL! :-)
