Andrew Sutton: Concepts Lite: Constraining Templates with Predicates
Channel: CppNow
Date: 2013-06-26

In this talk I introduce a new language feature being proposed for C++14: template constraints (a.k.a., concepts lite). A constraint is a predicate that determines whether or not a template argument can be used with a template. Using constraints, we can improve the declaration of templates by directly stating their requirements. We can also overload functions based on their constraints. Constraints allow type errors to be caught at the point use, meaning that scrolling through dense stacks of compiler errors will soon be a thing of the past.

As a language feature, template constraints are minimal and uncomplicated, emphasizing correctness of template use rather than the correctness of template definitions. This means that they can be adopted incrementally and easily into an existing code base.

The talk will cover examples of how to use constraints with generic algorithms and data structures, member functions and constructors, overloading, class template specialization, and the definition of constraints themselves. I will also discuss my experiences using constraints in day-to-day programming, including some good ideas and some not-so-good.

An experimental compiler based on GCC-4.8 will also be made available to the audience for experimentation.
---

*--*

---