errata - cpptt-book/2nd GitHub Wiki
C++テンプレートテクニック第2版 正誤情報
- 「リスト4-11 小さい機能単位で分ける」において、
add_lvalue_reference
メタ関数の実装で、T&
に対する部分特殊化を定義していました。これは、参照に対する参照になってしまうことを避けるためでした。しかし、C++11で右辺値参照が導入されたことにより、参照の重ねがけがひとつとして扱われる規則に変わりました。そのため、C++03ではT&
に対する部分特殊化は必要ですが、C++11以降では必要なくなりました。- 参照 : C++11 8.3.2 References [dcl.ref] パラグラフ5
There shall be no references to references
- 参照 : C++11 8.3.2 References [dcl.ref] パラグラフ6
If a typedef (7.1.3), a type template-parameter (14.3.1), or a decltype-specifier (7.1.6.2) denotes a type TR that is a reference to a type T, an attempt to create the type “lvalue reference to cv TR” creates the type “lvalue reference to T”, while an attempt to create the type “rvalue reference to cv TR” creates the type TR. [Example:
int i; typedef int& LRI; typedef int&& RRI; LRI& r1 = i; // r1 has the type int& const LRI& r2 = i; // r2 has the type int& const LRI&& r3 = i; // r3 has the type int& RRI& r4 = i; // r4 has the type int& RRI&& r5 = 5; // r5 has the type int&& decltype(r2)& r6 = i; // r6 has the type int& decltype(r2)&& r7 = i; // r7 has the type int&"
- 参照 : What does a reference-to-reference mean in C++? (Not an rvalue reference) - StackOverflow
- 参照 : C++11 8.3.2 References [dcl.ref] パラグラフ5