I was looking around how to make a lookup table and found this simple and elegant answer.
I didn't want to necro the thread, so I thought I'd make a new question. When trying to compile that answer in VS2015 I get the following errors:
template<int N>
struct Table
{
constexpr Table() : values()
{
// C3538 auto must always deduce the same type
// C3250 i declaration is not allowed in constexpr body
// C3249 illegal statement for sub-expression 'constexpr' function
for (auto i = 0; i < N; ++i)
{
values[i][0] = i;
values[i][1] = i * i * i;
}
}
int values[N][2];
};
int main(){
// defctor does not produce a constant value
constexpr auto a = Table<1000>();
return 0;
}
I tried to replace the C style array with an std::array
because I thought that might help with the iteration process. I also checked the code on some online compiler and it works there but not in VS.
What's the problem, and how could I replicate the solution without template bloating the code?