Please consider the following two overloads:
template<typename T, typename ...Args>
void f(std::vector<T>&& v, Args&& ...args)
{
std::cout << "f taking a vector + parameter pack\n";
}
template<typename ...Args>
void f(Args&& ...args)
{
std::cout << "f taking parameter pack\n";
}
Now, for the following fragment the expected overload is chosen:
std::vector<int> v{1, 2, 3};
f(std::move(v), 3.0);
(outputs: f taking a vector + parameter pack)
For the following case, the second overload is chosen:
std::vector<int> v{1, 2, 3};
f(v, 3.0);
(outputs: f taking a parameter pack)
The universal reference vector parameter binds to an lvalue reference as well, so why is it that the overload with just the parameter pack is being favored in this case?
Aucun commentaire:
Enregistrer un commentaire