5

でパラメーター化された関数テンプレートでは、引数の値のカテゴリに応じて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?
4

1 に答える 1

4

はい。autoテンプレートの実引数推定として正確に指定されます。

于 2011-08-11T09:41:11.203 に答える