The following code desperately needs : values() to compile, at least in ideone::C++14:
#include <iostream>
template<int N>
struct Table
{
constexpr Table() : values()
{
for (auto i = 0; i < N; ++i)
{
values[i] = i * i * i;
}
}
int values[N];
};
int main() {
constexpr auto a = Table<1000>();
for (auto x : a.values)
std::cout << x << '\n';
}
But why? I had thoughts along "values could also be initialized in a non-constexpr way and values() does explicitly say that we initialize it in a constexpr-compliant manner". But is not omitting : values() just as clear?
clanggives a strange message:assignment to object outside its lifetime is not allowed in a constant expressionfor the=in the constructor ofTableif I omitvalues().