# Standard library header <array>

From cppreference.com
< cpp‎ | header

This header is part of the containers library.

### Includes
`<initializer_list>`(C++11)
### Classes
array (C++11) | static contiguous array (class template)
std::tuple_size<std::array> | obtains the size of an `array` (class template specialization)
std::tuple_element<std::array> | obtains the type of the elements of `array` (class template specialization)
### Functions
operator==operator!=operator<operator<=operator>operator>= | lexicographically compares the values in the array (function template)
std::get(std::array) | accesses an element of an `array` (function template)
std::swap(std::array) (C++11) | specializes the std::swap algorithm (function template)

### Synopsis

    #include <initializer_list>

    namespace std {

        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 bool operator!=(const array<T,N>& x, const array<T,N>& y);
        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 bool operator>(const array<T,N>& x, const array<T,N>& y);
        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 bool operator>=(const array<T,N>& x, const array<T,N>& y);

        template <class T, size_t N>
            constexpr void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y)));

        template <class T> class tuple_size;
        template <size_t I, class T> class 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 std::array

    template <class T, size_t N >
    struct array {
        // types:
        typedef T&                               reference;
        typedef const T&                         const_reference;
        typedef /*implementation-defined*/       iterator;
        typedef /*implementation-defined*/       const_iterator;
        typedef size_t                           size_type;
        typedef ptrdiff_t                        difference_type;
        typedef T                                value_type;
        typedef T*                               pointer;
        typedef const T*                         const_pointer;
        typedef reverse_iterator<iterator>       reverse_iterator;
        typedef reverse_iterator<const_iterator> const_reverse_iterator;

        T elems[N]; // exposition only

        // no explicit construct/copy/destroy for aggregate type

        constexpr void fill(const T& u);
        constexpr void swap(array<T, N>&) 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:
        constexpr size_type size() const noexcept;
        constexpr size_type max_size() const noexcept;
        constexpr bool      empty() const noexcept;

        // element access:
        constexpr reference       operator[](size_type n);
        constexpr const_reference operator[](size_type n) const;
        constexpr const_reference at(size_type n) const;
        constexpr reference       at(size_type n);
        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)>;

##### Note

The name `array::elems` is only for exposition, it's not part of the interface.

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/header/array&oldid=110666"