“MPark.Patterns: Pattern Matching in C++”
summary
Library called MPark.Patterns implements pattern matching in C++17 as a header-only API using structured bindings, apply, visit and custom traits (tuple_size/variant_size). It provides as pattern, ds destructure, arg/wildcard, alternation, when-guards and a single-use variadic placeholder to match tuplelike/variantlike/any/pointerlike types. Example: expression-tree simplifier reuses shared_ptr nodes via arg and a fizzbuzz version generates the same assembly as hand-written code, so the prototype is practical though not optimized.
AI-written summary · about
chapters (25)
- 0:00Intro
- 3:14Standards Proposal
- 3:44Purpose
- 5:24Overview
- 6:04Algebraic Data Types
- 13:15Insight from Swift
- 14:56Matching Simple Types
- 15:39Matching Product Types
- 17:23Matching Sum Types
- 18:18Main Goals
- 19:56Basic Structure
- 21:23Re: Evaluating Expressions
- 23:29Optional Flag
- 26:43Patterns So Far
- 27:47Simplifying Expressions
- 28:44Simplifying int
- 35:07Putting it all together
- 36:21Identifiers
- 38:43Identifier Pattern
- 41:27Back to the Pattern Guard
- 42:32Variadic Pattern
- 43:26Inside of a template
- 44:18almost tuple_cat
- 58:20match_result-aware invoke
- 58:57Expression Pattern
related talks
51mSimple, Extensible Pattern Matching in C++14
01h 00m“Using Compile-time Code Generation to build an LLVM IR Pattern Matcher”
58mThe Pattern Matching We Already Have
01h 47mFunctional C++
54mPattern Matching in Java: Past, Present, Future
39mPattern Matching: Small Enhancement or Major Feature?
08mCompiling pattern matching to in-place modifications
23mPattern-matching on mutable values: danger!
