Linked Questions
21 questions linked to/from Programmatically create static arrays at compile time in C++
5 votes
1 answer
1k views
how to initialize a fixed size array and assign elements with a constexpr function in C++11 or with help of boost [duplicate]
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 ...
6 votes
1 answer
1k views
Initialize a const array in compile time with a template-based length [duplicate]
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 ...
355 votes
12 answers
670k views
Initialization of all elements of an array to one default value in C++?
C++ Notes: Array Initialization has a nice list over initialization of arrays. I have a int array[100] = {-1}; expecting it to be full with -1's but its not, only first value is and the rest are 0's ...
25 votes
7 answers
18k views
C++ convert integer to string at compile time
I want to do something like this: template<int N> char* foo() { // return a compile-time string containing N, equivalent to doing // ostringstream ostr; // ostr << N; // return ...
43 votes
8 answers
12k views
C++11: Compile Time Calculation of Array
Suppose I have some constexpr function f: constexpr int f(int x) { ... } And I have some const int N known at compile time: Either #define N ...; or const int N = ...; as needed by your answer. I ...
22 votes
4 answers
5k views
Modern C++: initialize constexpr tables
Suppose I have a class X, which functionality requires a lot of constant table values, say an array A[1024]. I have a recurrent function f that computes its values, smth like A[x] = f(A[x - 1]); ...
28 votes
3 answers
15k views
Create static array with variadic templates
There was an answer on stackoverflow (which I can't seem to find anymore) which demonstrated how a variadic template can be used in C++11 to create a static array at compile time: template <class ...
6 votes
4 answers
4k views
How to initialise a floating point array at compile time?
I have found two good approaches to initialise integral arrays at compile times here and here. Unfortunately, neither can be converted to initialise a float array straightforward; I find that I am ...
9 votes
5 answers
1k views
How to protect an array definition againt incomplete initialization with non-zero values?
I have a global array, which is indexed by the values of an enum, which has an element representing number of values. The array must be initialized by a special value, which unfortunately is not a 0. ...
7 votes
3 answers
10k views
C++ static const array initialization in template class
I have the following template class: template <unsigned N> class XArray { static const int Xdata[N]; }; I want to initialize the static const array for each XArray<N> I used, for ...
21 votes
1 answer
2k views
Alternatives for compile-time floating-point initialization
I'm currently working on a template-meta-programming based implementation of floating-point arithmetic. The template which represent compile-time float values is as follows: template<bool S , std::...
7 votes
1 answer
3k views
Initializing an array with a constexpr?
I wonder if it is possible to initialize an entire array with a constexpr function (with C++ 2011). Here I have something to illustrate what I want to do : template<unsigned int DIM> const ...
2 votes
2 answers
968 views
static compile time table with floating point values
Is it possible to generate an array at compile time, like in this nice answer of G. Fritzsche: Georg Fritzsche but with floating point values? I think its not possible in this manner because, the ...
2 votes
3 answers
1k views
Static arrays at compile time in C++
I was wondering if its possible to make the following answer more generic, in the sense that the type of the array be templated instead of just unsigned: I've enclosed the whole thing in a struct ...
3 votes
2 answers
600 views
Generating BitCount LUT at compile time
Let's say that I need to create a LUT containing precomputed bit count values (count of 1 bits in a number) for 0...255 values: int CB_LUT[256] = {0, 1, 1, 2, ... 7, 8}; If I don't want to use hard-...