I cite immediately the code for clarification:
struct S { S(int) {} }; int iArr[] = { 1, 2, 3 }; S sArr[] = { iArr[0], iArr[1], iArr[2] }; I want to avoid manually changing the initialization code of the sArr array when changing the number of values in iArr . Interests exactly compile-time initialization.
Is it possible? If so, how?
The options are interesting for both c ++ 03 (probably macros are not enough), and a modern approach (most likely variadic-templates ). If something suitable is expected in the new Standard, then it would also be nice to see in the answers.
std::make_index_sequence<countof(iArr)>to help. - Abyx