Template Parameters: Type and Value

We will explore the type and value type of template parameters in this lesson.

The template parameters that we have discussed so far have all been type parameters. Previously, parameters like T and ColorT represented types. For example, T meant int, double, Student, etc. depending on the instantiation of the template.

There are other kinds of template parameters like value, this, alias, and tuple.

Type template parameters

All of the templates that you have seen so far have had type parameters.

Value template parameters

Value template parameters allow flexibility on certain values used in the template implementation.

Since templates are a compile-time feature, the values for the value template parameters must be known at compile-time; values that must be calculated at run time cannot be used.

To see the advantage of value template parameters, let’s start with a set of structs representing geometric shapes:

Get hands-on with 1000+ tech skills courses.