I am trying to create variadic template that can get lvalues, rvalues and rvalue references as arguments. But it seems that T&& is treated as rvalue reference and wouldn't accept other types.
Am I missing something? I thought that && is universal reference when used in templates.
#include <string>
template <typename... T>
struct MyClass
{
MyClass(T&&... values)
{
}
};
int main()
{
std::string string_value;
//MyClass my_class(string_value); // class template argument deduction failed
//MyClass<std::string> my_class(string_value); // cannot bind rvalue reference of type
MyClass<std::string> my_class(std::move(string_value)); // OK
return 0;
}
That's not a universal/forwarding reference.
From cppreference: