How can I initialize a vector in the initializer list of a varargs constructor?
c++, constants, initializer-list, variadic-functions, vector
Solution
You can't. Make `Foo` a variadic template instead:
template <typename ...ArgumentTypes>
Foo(ArgumentTypes&& args...):
bars({std::forward<ArgumentTypes>(args)...})
{
}
This uses the initializer-list constructor of the vector.
Problem
I need to elaborate the constructor of the following class: ``` class Foo { public: const std::vector<Bar> bars; Foo(int num_bars, ...); } ``` Assume for the sake of discussion that the extra argument are all `const Bar&` or just `Bar`. I need to initialize v on construction with the bars in the va_list. How can I do that?