Template Arguments
Explore how C++ automatically deduces template arguments for function templates, including references, pointers, and universal references. Understand when explicit template arguments are required, how default arguments work, and new features introduced in C++17 that simplify template argument deduction for constructors.
We'll cover the following...
We'll cover the following...
Template Arguments
In general, template arguments can be automatically deduced for function templates. From the user’s perspective, function templates feel like functions.
Conversion:
- The compiler uses simple conversions for deducing the template arguments from the function arguments.
- The compiler removes
constorvolatilefrom the function arguments and converts C-arrays and functions to pointers.
Template argument deduction for function templates:
template <typename T>
void func(ParamType param);
Two datatypes were deduced:
TParamType
ParamType can be a
- Reference or pointer
- Universal