【发布时间】:2011-08-11 09:39:39
【问题描述】:
在以T 参数化的函数模板中,T&& 类型可能是也可能不是右值引用,具体取决于参数的值类别:
template <typename T>
void function(T&& x)
{
// ...
}
std::string some_named_string;
function(some_named_string); // T&& is std::string&
function(std::string("hello")); // T&& is std::string&&
同样的规则是否也适用于自动推断类型的局部变量?
auto&& x = some_named_string; // is x a std::string& here?
auto&& y = std::string("hello"); // is y a std::string&& here?
【问题讨论】:
标签: c++ templates c++11 type-inference rvalue-reference