Have you registered for CppCon 2016 in September? Don’t delay – Registration is open now.
While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2015 for you to enjoy. Here is today’s feature:
Simple, Extensible Pattern Matching in C++14
by John R. Bandela
Summary of the talk:
Recently, there has been in increased interest in applying functional programming techniques to C++. A very convenient construct that is used in functional programming languages is pattern matching. Due to the features introduced in C++11 and C++14 we can actually write a simple, easy to use, understandable, and extensible pattern matching library that is header only and uses no macros.
In this talks we will discuss the motivations for pattern matching, and see examples of use from other languages. We will then go on to design and implement a pattern matching library in C++. Particular attention will be payed to new C++14 features that greatly simplify the implementation such as integer_sequence, function return type deduction, and generic lambdas. The implementation will also serve a practical guide to using variadic templates and std::tuple.
We will show how the library can be easily extended and customized by working through some examples of customization such as working with user defined classes and structs, pointers, tuples, boost::optional, and boost::variant. At the end of the session, the audience will have an appreciation for pattern matching, as well as a sense that the C++11/14 features open new paradigms without sacrificing understandable code.
Add a Comment
Comments are closed.