We know that C++ allows initialization of C-style arrays with zeros:
int a[5] = {0};
// or
int a[5] = {};
The same works for std::array
std::array a<int, 5> = {};
However, this won't work:
int a[5] = {33}; // in memory( 33, 0, 0, 0, 0 )
std::array<int, 5> = {33}; // in memory( 33, 0, 0, 0, 0 )
Is there any way to initialize the whole array with a non-zero value without using vector or algorhtm?
Maybe constexpr could help? What would be the best solution?
P.S.:
GCC offers this syntax
int a[5] = {[0 ... 4] = 33};
but I am not sure if it is valid for other compilers.