C++ using pack template parameters code example

Example: variadic templates

template<class... Args>
void Foo(Agrs*... arguments);

template<class... Args>
class A;

/* Variadic templates can be used to allow a multitude of variations
of a class or function to be compiled without having to explicitly
state what the required amount of template parameters are.

In order to use the parameter pack you need to unpack it. This can be
done through C++17 fold expressions or using recursion:*/

template<typename Arg>
void Foo(Arg* arg)
{
  // do something.
}

template<typename Arg, typename... Args>
void Foo(Arg* arg, Args*... args)
{
  Foo(arg);
  Foo(args);
}

Tags:

Cpp Example