Template Parameters: Type and Value
The template parameters that we have discussed so far have all been type parameters. Previously, parameters like
ColorT represented types. For example,
Student, etc. depending on the instantiation of the template.
There are other kinds of template parameters like
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: