template

C++ Function Templates with Examples

In this tutorial we will give an introduction to C++ function templates and provide simple function template examples and a more complex sort predicates example with generic sorting template function. And to the end, there are some examples on C++ template function specialization.

Parameterized constraints

There are two kinds of parameterized constraints, one to check if an expression between two operands are allowed, and one for checking a constant value. It’s not legal to put a constraint on non-constant values.

Exception constraints

Exception constraints check if an expression E is marked noexcept, and returns true only if it evaluates to noexcept(true).

Function and variable concepts

In general, there are two kinds of distinct concepts. Those are function concepts and variable concepts. They are similar to their non-concept siblings template functions and template variables. If you haven’t heard about template variables, you’re not alone. Those are new in C++14, and allows you to define a variable as a template. However, variable concepts are modeled around template variables, so they will be covered.

C++ Concepts: New keywords

The concepts extension introduces 5 new keywords. Only concept and requires are implemented, though the GCC documentation states there are 5 new keywords, only 2 are real keywords at the moment.