...

/

Using Concepts to Constrain Auto Parameters

Using Concepts to Constrain Auto Parameters

Learn to simplify function template syntax and employ concepts to constrain the template arguments.

We'll cover the following...

In the “Template Fundamentals” section, we discussed generic lambdas, introduced in C++14, as well as lambda templates, introduced in C++20. A lambda that uses the auto specifier for at least one parameter is called a generic lambda. The function object generated by the compiler will have a templated call operator. Here’s an example to refresh our memory:

auto lsum = [](auto a, auto b) {return a + b; };

Abbreviated function templates

The C++20 standard generalizes this feature for all functions. We can use the auto specifier in the function parameter list. This has the effect of transforming the function into a template function. Here’s an ...