Linked Questions

5 votes
1 answer
1k views

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 ...
liuyanghejerry's user avatar
6 votes
1 answer
1k views

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 ...
Yoav's user avatar
  • 6,138
355 votes
12 answers
670k views

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 ...
Milan's user avatar
  • 15.9k
25 votes
7 answers
18k views

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 ...
Andrey's user avatar
  • 858
43 votes
8 answers
12k views

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 ...
Andrew Tomazos's user avatar
22 votes
4 answers
5k views

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]); ...
Aleksandr Samarin's user avatar
28 votes
3 answers
15k views

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 ...
Channel72's user avatar
  • 24.9k
6 votes
4 answers
4k views

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 ...
Zsar's user avatar
  • 493
9 votes
5 answers
1k views

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. ...
fork0's user avatar
  • 3,459
7 votes
3 answers
10k views

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 ...
Oliver Q's user avatar
  • 123
21 votes
1 answer
2k views

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::...
Manu343726's user avatar
  • 14.2k
7 votes
1 answer
3k views

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 ...
Vincent's user avatar
  • 61.1k
2 votes
2 answers
968 views

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 ...
Gabriel's user avatar
  • 9,562
2 votes
3 answers
1k views

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 ...
Xander Tulip's user avatar
  • 1,498
3 votes
2 answers
600 views

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-...
Alex F's user avatar
  • 43.5k

15 30 50 per page