This event has ended. Visit the official site or create your own event on Sched.
Back To Schedule
Tuesday, September 26 • 2:00pm - 3:00pm
MPark.Patterns: Pattern Matching in C++

Log in to save this to your schedule, view media, leave feedback and see who's attending!

Feedback form is now closed.
Pattern matching brings a declarative approach to destructuring and inspecting complex data types. It’s a very powerful abstraction provided by many programming languages such as Haskell and OCaml, and more recently, Rust, Scala, and Swift.

We’ll see a glimpse of pattern matching in C++17 and their current limitations through features such as structured bindings, `apply`, and `visit`. We’ll then jump into MPark.Patterns, an experimental pattern matching library for C++. The following is an example of `fizzbuzz` written with the library:

void fizzbuzz() {
   for (int i = 1; i <= 100; ++i) {
    using namespace mpark::patterns;
    match(i % 3, i % 5)(
      pattern(0, 0) = [] { std::cout << "fizzbuzz\n"; },
      pattern(0, _) = [] { std::cout << "fizz\n"; },
      pattern(_, 0) = [] { std::cout << "buzz\n"; },
      pattern(_, _) = [i] { std::cout << i << '\n'; });

We’ll see many more examples like this that lead to simpler, declarative code that focuses on the desired shape/state of the data, rather than a sequence of imperative code that tries to inspect the data in piecemeal.

The goal of the library, and the talk is to gain experience and exposure to pattern matching in order to potentially help guide the design of a language-based pattern matching mechanism.

avatar for Michael Park

Michael Park

Software Engineer, Facebook
I'm a software engineer at Facebook, working on the C++ libraries and standards team. My focus for C++ is to introduce pattern matching to facilitate better code.

Tuesday September 26, 2017 2:00pm - 3:00pm PDT
Manchester (407) Meydenbauer Center