Standard library header <array> (C++11)

From cppreference.com
< cpp‎ | header
 
 
Standard library headers
Language support
Concepts
<concepts> (C++20)
Diagnostics
<system_error> (C++11)

Memory management
<memory_resource> (C++17)  
Metaprogramming
<type_traits> (C++11)
<ratio> (C++11)
General utilities
<utility>
<tuple> (C++11)
<optional> (C++17)
<variant> (C++17)
<any> (C++17)
<expected> (C++23)
<bitset>

<charconv> (C++17)
<format> (C++20)
<bit> (C++20)

Strings
<cuchar> (C++11)

Containers
<array> (C++11)
<deque>
<forward_list> (C++11)
<list>
<flat_set> (C++23)
<span> (C++20)
<mdspan> (C++23)

Iterators
<iterator>
Ranges
<ranges> (C++20)
<generator> (C++23)
Algorithms
Numerics
<cfenv> (C++11)
<complex>
<numbers> (C++20)

Time
<chrono> (C++11)
Localization
<codecvt> (C++11/17*)
Input/output
<filesystem> (C++17)
<cstdio>
<cinttypes> (C++11)
<strstream> (C++98*)
Regular expressions
<regex> (C++11)
Concurrency support
<stop_token> (C++20)
<thread> (C++11)
<atomic> (C++11)
<stdatomic.h> (C++23)
<mutex> (C++11)
<shared_mutex> (C++14)
<condition_variable> (C++11)  
<semaphore> (C++20)
<latch> (C++20)
<barrier> (C++20)
<future> (C++11)

C compatibility
<cstdbool> (C++11/17/20*)  
<ccomplex> (C++11/17/20*)
<ctgmath> (C++11/17/20*)

<cstdalign> (C++11/17/20*)

<ciso646> (until C++20)

 

This header is part of the containers library.

Includes

(C++20)
Three-way comparison operator support
std::initializer_list class template

Classes

(C++11)
static contiguous array
(class template)
obtains the number of elements of a tuple-like type
(class template)
obtains the element types of a tuple-like type
(class template)
obtains the size of an array
(class template specialization)
obtains the type of the elements of array
(class template specialization)

Functions

(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values in the array
(function template)
specializes the std::swap algorithm
(function template)
(C++20)
creates a std::array object from a built-in array
(function template)
accesses an element of an array
(function template)
Range access
(C++11)(C++14)
returns an iterator to the beginning of a container or array
(function template)
(C++11)(C++14)
returns an iterator to the end of a container or array
(function template)
returns a reverse iterator to the beginning of a container or array
(function template)
(C++14)
returns a reverse end iterator for a container or array
(function template)
(C++17)(C++20)
returns the size of a container or array
(function template)
(C++17)
checks whether the container is empty
(function template)
(C++17)
obtains the pointer to the underlying array
(function template)

Synopsis

#include <compare>
#include <initializer_list>
 
namespace std
{
    // class template array
    template<class T, size_t N> struct array;
 
    template<class T, size_t N>
        constexpr bool operator==(const array<T, N>& x, const array<T, N>& y);
    template<class T, size_t N>
        constexpr __synth_three_way_result<T>
            operator<=>(const array<T, N>& x, const array<T, N>& y);
 
    // specialized algorithms
    template<class T, size_t N>
        constexpr void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
 
    // array creation functions
    template<class T, size_t N>
        constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);
    template<class T, size_t N>
        constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]);
 
    // tuple interface
    template<class T> struct tuple_size;
    template<size_t I, class T> struct tuple_element;
    template<class T, size_t N>
        struct tuple_size<array<T, N>>;
    template<size_t I, class T, size_t N>
        struct tuple_element<I, array<T, N>>;
    template<size_t I, class T, size_t N>
        constexpr T& get(array<T, N>&) noexcept;
    template<size_t I, class T, size_t N>
        constexpr T&& get(array<T, N>&&) noexcept;
    template<size_t I, class T, size_t N>
        constexpr const T& get(const array<T, N>&) noexcept;
    template<size_t I, class T, size_t N>
        constexpr const T&& get(const array<T, N>&&) noexcept;
}

Class template std::array

namespace std
{
    template<class T, size_t N>
    struct array
    {
        // types
        using value_type             = T;
        using pointer                = T*;
        using const_pointer          = const T*;
        using reference              = T&;
        using const_reference        = const T&;
        using size_type              = size_t;
        using difference_type        = ptrdiff_t;
        using iterator               = /* implementation-defined */;
        using const_iterator         = /* implementation-defined */;
        using reverse_iterator       = std::reverse_iterator<iterator>;
        using const_reverse_iterator = std::reverse_iterator<const_iterator>;
 
        // no explicit construct/copy/destroy for aggregate type
 
        constexpr void fill(const T& u);
        constexpr void swap(array&) noexcept(is_nothrow_swappable_v<T>);
 
        // iterators
        constexpr iterator               begin() noexcept;
        constexpr const_iterator         begin() const noexcept;
        constexpr iterator               end() noexcept;
        constexpr const_iterator         end() const noexcept;
 
        constexpr reverse_iterator       rbegin() noexcept;
        constexpr const_reverse_iterator rbegin() const noexcept;
        constexpr reverse_iterator       rend() noexcept;
        constexpr const_reverse_iterator rend() const noexcept;
 
        constexpr const_iterator         cbegin() const noexcept;
        constexpr const_iterator         cend() const noexcept;
        constexpr const_reverse_iterator crbegin() const noexcept;
        constexpr const_reverse_iterator crend() const noexcept;
 
        // capacity
        [[nodiscard]] constexpr bool empty() const noexcept;
        constexpr size_type size() const noexcept;
        constexpr size_type max_size() const noexcept;
 
        // element access
        constexpr reference       operator[](size_type n);
        constexpr const_reference operator[](size_type n) const;
        constexpr reference       at(size_type n);
        constexpr const_reference at(size_type n) const;
        constexpr reference       front();
        constexpr const_reference front() const;
        constexpr reference       back();
        constexpr const_reference back() const;
 
        constexpr T*       data() noexcept;
        constexpr const T* data() const noexcept;
    };
 
    template<class T, class... U>
        array(T, U...) -> array<T, 1 + sizeof...(U)>;
}