Originally Posted by
whiteflags
Does this do what I think it does? It is NOT NOT NOT a good idea to fill a list by using a function with 10000 arguments.
If you mean that it recursively calls the function once for each argument? Then yes.
But then again, would you type out 10 000 arguments in the call to that function? I sure as heck wouldn't. And that's really the only use of it, anyway.
But then again, that got me thinking. Why use variadic templates when all arguments are of the same type?
If that's the case, then the follow would suffice:
Code:
template<typename C, typename Elem> void push_back(C& c, std::initializer_list<Elem> values)
{
for (const auto & elem : values)
c.push_back(elem);
}
auto args = { 1, 2, 2, 3, 4, 2, 3, 3, 5, 1, 0 };
push_back(the_list, args);
(Again, C++11 features.)
EDIT2:
But then again, it might be a good idea to use r-values in the function since I would be passing temporaries in most of the cases (that's really what I designed it for), so a better version might be:
Code:
template<typename C, typename Elem, typename... T> void push_back(C& c, const Elem& value, const T&&... values)
{
c.push_back(value);
push_back(c, std::move(values)...);
}
template<typename C> void push_back(C& c) {}