Possible Duplicate:
Programmatically create static arrays at compile time in C++
Is it possible to initialize the following array in compile time?
template<int n> void
foo()
{
static int pairs[2*n]; // = {0,0, 1,1, ..., n-1,n-1}
for (int i = 0; i < n; i++)
{
pairs[2*i] = pairs[2*i+1] = i;
}
do_something_with_pairs(pairs);
}
(I use Clang on Xcode 4.5 so C++11 is OK)