2

Similar to a standard array:

int A[] = {1,2,3,4};

The problem I have is that a std::array that is initialized, must match the size and the number of initialization elements manually, which is bad.

I know I could construct my own array with an initializer list and do something similar, but it would not be a static array. I was hoping the C++11 standard required that to still be possible but I can't figure the syntax if it is, and I can't find anything in the standard confirming one way or the other (I can never find anything in the standard!).

Frigg
  • 369
  • 1
  • 3
  • 12
  • 1
    Isn't `std::make_array` coming in C++14 or C+17? – fredoverflow May 13 '14 at 14:51
  • You can do this with a variadic macro. I'm having dinner but Fred can possibly post such solution for you if you're interested. – Cheers and hth. - Alf May 13 '14 at 14:54
  • +1 to counter silly downvote. – Cheers and hth. - Alf May 13 '14 at 14:54
  • 2
    -1 to counter silly counter downvote. – Shoe May 13 '14 at 14:57
  • 4
    I prefer it when people vote for the content, not for the already existing votes. – R. Martinho Fernandes May 13 '14 at 14:58
  • @Jeffrey: explain your downvote so that readers (and the OP) can learn from your insight. – Cheers and hth. - Alf May 13 '14 at 15:13
  • @Fred: Note that none of the alleged answers given for the duplicate question are answers. None of them guarantee avoiding extra copying, and they don't handle string literals or struct initializers. This is not difficult to do via preprocessing though: an argument counting macro was posted to [comp.lang.c] already in 2000 or thereabouts. – Cheers and hth. - Alf May 13 '14 at 15:34
  • Thank you @FredOverflow, that is just what I needed ... in C++11 thought. I was not really interested to know how to emulate it; it is ugly and not flexible. My question was really about the C++11 standard. From everyone's answer I am assuming it is not possible by the standard. I am really sad about this, because it makes it totally useless for me. And before we move to C++14/C++17 I'll be dead! – Frigg May 14 '14 at 16:19

0 Answers0