array

This header is part of the containers library.

Includes

<initializer_list>(C++11)

Classes

(since C++11)
static contiguous array
(class template)
obtains the size of an array
(class template specialization)
obtains the type of the elements of array
(class template specialization)

Functions

lexicographically compares the values in the array
(function template)
accesses an element of an array
(function template)
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>
        bool operator==(const array<T,N>& x, const array<T,N>& y);
    template <class T, size_t N>
        bool operator!=(const array<T,N>& x, const array<T,N>& y);
    template <class T, size_t N>
        bool operator<(const array<T,N>& x, const array<T,N>& y);
    template <class T, size_t N>
        bool operator>(const array<T,N>& x, const array<T,N>& y);
    template <class T, size_t N>
        bool operator<=(const array<T,N>& x, const array<T,N>& y);
    template <class T, size_t N>
        bool operator>=(const array<T,N>& x, const array<T,N>& y);
 
    template <class T, size_t N >
        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> T& get(array<T, N>&) noexcept;
    template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept;
    template <size_t I, class T, size_t N> 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
 
    void fill(const T& u);
    void swap(array<T, N>&) noexcept(noexcept(swap(declval<T&>(), declval<T&>())));
 
    // iterators:
    iterator                begin() noexcept;
    const_iterator          begin() const noexcept;
    iterator                end() noexcept;
    const_iterator          end() const noexcept;
 
    reverse_iterator        rbegin() noexcept;
    const_reverse_iterator  rbegin() const noexcept;
    reverse_iterator        rend() noexcept;
    const_reverse_iterator  rend() const noexcept;
 
    const_iterator          cbegin() noexcept;
    const_iterator          cend() noexcept;
    const_reverse_iterator  crbegin() const noexcept;
    const_reverse_iterator  crend() const noexcept;
 
    // capacity:
    constexpr size_type size() noexcept;
    constexpr size_type max_size() noexcept;
    constexpr bool      empty() noexcept;
 
    // element access:
    reference       operator[](size_type n);
    const_reference operator[](size_type n) const;
    const_reference at(size_type n) const;
    reference       at(size_type n);
    reference       front();
    const_reference front() const;
    reference       back();
    const_reference back() const;
 
    T *       data() noexcept;
    const T * data() const noexcept;
};
Note

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

doc_CPP
2016-10-11 09:57:32
Comments
Leave a Comment

Please login to continue.