次のプログラムを検討してください。
int main ()
{
const int e = 10;
for (decltype(e) i{0}; i < e; ++i) {
// do something
}
}
これはclang(およびgcc)でコンパイルできません:
decltype.cpp:5:35: error: read-only variable is not assignable
for (decltype(e) i{0}; i < e; ++i) {
^ ~
i基本的に、コンパイラはそれが const でなければならないと仮定していeます。
decltypeの型を取得するために使用できる方法はありますeが、指定子を削除しconstますか?