logoalt Hacker News

stackghostyesterday at 6:23 PM2 repliesview on HN

>How do you make an std::array of a given type? Wrap the existing type in an extra layer of std::array, we all know this

huh? where is the extra layer?

    std::array<int, 5> array_of_ints = { 1, 2, 3, 4, 5 };
>How do you make a C-array of a given type? Oh boy, "prepend the array specifier before the list of existing array specifiers"

?

    int c_style_array[5] = {2, 3, 5, 7, 11};

Replies

ueckeryesterday at 6:30 PM

I assume he means multi-dimensional arrays:

    std::array<std::array<int, 3>, 5> array_of_ints;
    int c_style_array[5][3];
But the C-style array is more readable, so I am not sure what the complaint really is about.
show 1 reply
saghmyesterday at 7:05 PM

The "existing type" in your example is int, the "extra layer" is the array type that "wraps" it

show 1 reply