Template Arguments

In this lesson, we'll learn about template arguments.

Template Arguments

Template arguments can, in general, automatically be deduced for function templates. The compiler deduces the template arguments for the function arguments. 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 const or volatile from 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:

  • T
  • ParamType

ParamType can be

  • Reference or pointer
  • Universal reference(&&)
  • Value (copy)

Get hands-on with 1000+ tech skills courses.