lundi 21 mai 2018

Is it possible to expand non-variadic arguments in a variadic template function?

It is probably easier to explain what I mean by an example. Imagine a following template:

template <class... Args>
std::tuple<Args...> foo();

It can be invoked, for example, like this:

auto ret = foo<int, bool>();

But what if I want to pass additional arguments to the function, based on the number of variadic template arguments? For example, let's say I want to pass a character string literal for every Args:

auto ret = foo<int, bool>("a", "b");

The problem with this, is that it does not seem possible to expand non-variadic arguments, so the following obviously doesn't compile:

template <class... Args>
std::tuple<Args...> foo(const char*... names);

Is there any sensible way to implement this?

Aucun commentaire:

Enregistrer un commentaire