std::array : safe C arrays

The std::array was a new container introduced in C++11. A std::array works in the same way as a plain old C array (like int values[5]) but has the advantage that it will not decay into a plain pointer.

Unlike the vector can an array not be resized once it has been created.

Creating

std::array is always allocated on the stack. It it allocated using uniform initialization:

Iterating

You can iterate through each of the values in the array using range-based for:

or using std::for_each and a lambda

Facebookgoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *