std::array (3) - Linux Manuals
std::array: std::array
NAME
Synopsis
Defined in header <array>
template<
class T, (since C++11)
std::size_t N
> struct array;
std::array is a container that encapsulates fixed size arrays.
This container is an aggregate type with the same semantics as a struct holding a C-style_array T[N] as its only non-static data member. Unlike a C-style array, it doesn't decay to T* automatically. As an aggregate type, it can be initialized with aggregate-initialization given at most N initializers that are convertible to T: std::array<int, 3> a = {1,2,3};.
The struct combines the performance and accessibility of a C-style array with the benefits of a standard container, such as knowing its own size, supporting assignment, random access iterators, etc.
std::array satisfies the requirements of Container and ReversibleContainer except that default-constructed array is not empty and that the complexity of swapping is linear,
satisfies the requirements of ContiguousContainer,
(since C++17) and partially satisfies the requirements of SequenceContainer.
There is a special case for a zero-length array (N == 0). In that case, array.begin() == array.end(), which is some unique value. The effect of calling front() or back() on a zero-sized array is undefined.
An array can also be used as a tuple of N elements of the same type.
Iterator invalidation
As a rule, iterators to an array are never invalidated throughout the lifetime of the array. One should take note, however, that during swap, the iterator will continue to point to the same array element, and will thus change its value.
Member types
Member type Definition
value_type T
size_type std::size_t
difference_type std::ptrdiff_t
reference value_type&
const_reference const value_type&
pointer value_type*
const_pointer const value_type*
iterator (since C++20)
const_iterator (since C++20)
reverse_iterator std::reverse_iterator<iterator>
const_reverse_iterator std::reverse_iterator<const_iterator>
Member functions
Implicitly-defined member functions
constructor initializes the array following the rules of aggregate_initialization (note that default initialization may result in indeterminate values for non-class T)
(implicitly declared)
destructor destroys every element of the array
(implicitly declared)
operator= overwrites every element of the array with the corresponding element of another array
(implicitly declared)
Element access