Template Parameters: Tuple

Get to learn about the tuple template parameters.

We'll cover the following

Tuple

In the variable number of parameters chapter that variadic functions can take any number and any type of parameters. For example, writeln() can be called with any number of parameters of any type.

Templates can be variadic as well. A template parameter that consists of a name followed by ... allows any number and kind of parameters at that parameter’s position. Such parameters appear as a tuple inside the template, which can be used like an AliasSeq.

Let’s see an example of this with a template that simply prints information about every template argument that it is instantiated with:

void info(T...)(T args) {
    // ...
}

The template parameter T... makes info a variadic template. Both T and args are tuples:

  • T represents the types of the arguments.

  • args represents the arguments themselves.

The following example instantiates that function template with three values of three different types:

Get hands-on with 1000+ tech skills courses.