関数fooとする:
template< typename T >
void foo( T&& a ){}
T次の の呼び出しで推定される型は次のとおりですfoo。
foo( 0 ); // is T here int or int&& ?
int a = 0;
foo( a ); // is T here int or int& ?
関数fooとする:
template< typename T >
void foo( T&& a ){}
T次の の呼び出しで推定される型は次のとおりですfoo。
foo( 0 ); // is T here int or int&& ?
int a = 0;
foo( a ); // is T here int or int& ?
あなたが提供したような推測されたコンテキストT&&での式
template< typename T >
void foo( T&& a ){}
つまり、T は指定された引数に基づいて推定され、 参照の折りたたみ規則に従います。
要するに;
指定された引数がtypeの左辺値typeである場合、T&&
展開されtype& &&、折りたたまれますtype&
提供された引数がtypeの右辺値typeである場合、T&&
に展開さtype &&れます。type&&
両方とも参照であることに注意してください。別の関数の右辺値オーバーロードをトリガーする必要がある場合は、次のようにする必要があります。std::forward<T>(a)