原則として、decltype
constness を保持します。
const int ci = 0;
decltype(ci) x; // x is const int
x = 5; // error--x is const
class Gadget{}:
const Gadget makeCG(); // factory
decltype(makeCG()) y1, y2; // y1 and y2 are const Gadgets
y1 = y2; // error--y1 is const
しかし、const
基本的な型を返す戻り値の型についてdecltype
は、捨てるようconst
です:
const int makeCI(); // factory
decltype(makeCI()) z; // z is NOT const
z = 5; // okay
decltype
この場合、consness を破棄するのはなぜですか? 私は2つの意味で質問を意味します:
- 標準のどの部分でこの動作が指定されていますか?
- このように動作を指定する動機は何ですか?
ありがとう。