Skip to the content of the web site.

std::array

std::array

The array class is very similar to the primitive array that may be defined as a local variable:

    // A primitive array of 10 items
    double data[10]{};

    // An instance of the std::array
    // class with 10 items
    std::array more_data{};

The amount of memory allocated to both these arrays is fixed, but the container std::array can be both passed to functions, but can also be a return value of a function. No function can return a primitive array. It must be possible for the compiler to determine the value of the capacity of the array while the compiler is generating the executable. You cannot, for example, create such an array based on the input of the user.

In a primitive array, there are no operations that are performed, and there isn't even array bounds checking. This class allows the user to choose whether or not to use bound checking by allowing access without bounds checking using the same indexing notation as primitive arrays, but performs bound checking with a special member function at( ... ).

You can see the use of the std::array class at replit.com.