Templates
Function Templates
A template is a pattern the compiler uses to expand into actual code. Rather than writing out a completed function yourself, you write a general outline contain…
Class Templates
One most used example is when you need to have a pair of values of the same type. It is just too frequent to write a struct for each type. Here's what we get fo…
Template Argument Deduction
When a function template is invoked, the compiler is often able to deduce the template type by itself. That process is called template argument deduction. It al…
Non-Type Template Parameters
While most template parameters are types, a template can also take ordinary non type values that are known at compile time. Those non type template parameters a…
Template Specialization
Sometimes a generic template does the wrong thing for a single specific type. It's necessary for the compiler to have a function or a class for this specific ty…
Variadic Templates
Writing a function template that accepts exactly two arguments is straightforward, but useful operations often take three, or four, or many. It’s unfeasible to…
Parameter Packs and Fold Expressions
A parameter pack is simply a collection of zero or more template arguments that the compiler treats as a single entity. Whatever they are, something then has to…
Type Traits
A type trait is a simple template that, during compilation, provides an answer to a question concerning a type. The answer is a type or a Boolean value that oth…
SFINAE
A template that looks correct may fail if the compiler tries to substitute a particular type into it. Under normal rules, the failure would be a hard error and…