You can do this, but it's a bit of a circular motion since you are writing the expression directly. You must call push_back once for each argument in the argument list of the variational pattern.
How do you achieve this? Well, calling the recursive function once for each template argument:
template <typename Base, typename T1, typename T2, typename... T> void fill(std::vector<Base*>& vec) { vec.push_back(new T1); fill<Base, T2, T...>(vec); } template <typename Base, typename T1> void fill(std::vector<Base*>& vec) { vec.push_back(new T1); }
Here we have two overloads of the fill function, one with a variational list of template arguments and one without it is the case of a recursion base. As long as there are at least two template arguments, the first version is called. If only one argument is left, the second argument is called instead.
In the constructor, call it like this:
fill<TestCase, T...>(test_cases);
Konrad Rudolph
source share