5

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.

2

1 Answer 1

1

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 }; 
};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.