I have a (templated) function like this:
template<typename T>
void func(std::initializer_list<std::vector<T>> args)
{
for (const auto &values : inputValues)
{
someOperation(values);
}
}
But I'm pretty sure this is not what I want. What I want is a function that can receive an arbitrary number of std:vector<T>
s avoiding copies (in fact, they should be received as const
since I am not modifying them inside). Ideally, I would like to be able to pass both rvalues and lvalues, like:
std::vector<int> myVec {1, 2, 3};
func({myVec, {4, 5}});
The problem that I have with the current declaration is that I think (although I have not found any source explicitly confirming or refuting this) that, as it is right now, the initializer list will copy the vectors on creation (I know that they would not get copied when the initialization list itself is copied in any case); is this correct? If that is the case, is:
template<typename T>
void func(std::initializer_list<const & std::vector<T>> args)
{
// ...
}
What I am looking for? And would that allow me to use rvalues? I am open to options different than initializer lists (I'm not sure I'd be able to use variadic templates, because this function template is explicitly instantiated and compiled into a library, but if there is an alternative with that it would be interesting to see).