Possible Duplicate:
Programmatically create static arrays at compile time in C++
I have lots of data to be stored in a fixed array, with its elements depend on position. The value of each element can be calculated at compile time.
My code is almost like:
int fun(int p) // maybe constexpr
{
return 0x1<<p;
}
int a[17] = {
repeat_fun_from_0_to_16();
};
Since all of the value can be determined at compile time, there should be a way to do this, I guess.
I also checked out there's a repeat()
in boost.assignment, but don't know how to use it with this situation.
Thanks to @aleguna , I've solved this problem by this answer.
All I need to change is the meta function:
template<size_t index> struct MetaFunc {
enum { value = index << 1 };
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With