You were redirected to || See search results for: "array"
class template


template < class T, size_t N > class array;
Array class
Arrays are fixed-size sequence containers: they hold a specific number of elements ordered in a strict linear sequence.

Internally, an array does not keep any data other than the elements it contains (not even its size, which is a template parameter, fixed on compile time). It is as efficient in terms of storage size as an ordinary array declared with the language's bracket syntax ([]). This class merely adds a layer of member and global functions to it, so that arrays can be used as standard containers.

Unlike the other standard containers, arrays have a fixed size and do not manage the allocation of its elements through an allocator: they are an aggregate type encapsulating a fixed-size array of elements. Therefore, they cannot be expanded or contracted dynamically (see vector for a similar container that can be expanded).

Zero-sized arrays are valid, but they should not be dereferenced (members front, back, and data).

Unlike with the other containers in the Standard Library, swapping two array containers is a linear operation that involves swapping all the elements in the ranges individually, which generally is a considerably less efficient operation. On the other side, this allows the iterators to elements in both containers to keep their original container association.

Another unique feature of array containers is that they can be treated as tuple objects: The <array> header overloads the get function to access the elements of the array as if it was a tuple, as well as specialized tuple_size and tuple_element types.

Container properties

Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by their position in this sequence.
Contiguous storage
The elements are stored in contiguous memory locations, allowing constant time random access to elements. Pointers to an element can be offset to access other elements.
Fixed-size aggregate
The container uses implicit constructors and destructors to allocate the required space statically. Its size is compile-time constant. No memory or time overhead.

Template parameters

Type of the elements contained.
Aliased as member type array::value_type.
Size of the array, in terms of number of elements.
In the reference for the array member functions, these same names are assumed for the template parameters.

Member types

The following aliases are member types of array. They are widely used as parameter and return types by member functions:

member typedefinitionnotes
value_typeThe first template parameter (T)
const_referenceconst value_type&
const_pointerconst value_type*
iteratora random access iterator to value_typeconvertible to const_iterator
const_iteratora random access iterator to const value_type
size_typesize_tunsigned integral type
difference_typeptrdiff_tsigned integral type

Member functions



Element access


Non-member function overloads

Non-member class specializations