Standard library header <array> (C++11)
From cppreference.com
This header is part of the containers library.
Includes | ||
(C++20) | Three-way comparison operator support | |
(C++11) | std::initializer_list class template | |
Classes | ||
(C++11) | fixed-sized inplace contiguous array (class template) | |
(C++11) | obtains the number of elements of a tuple-like type (class template) | |
(C++11) | obtains the element types of a tuple-like type (class template) | |
(C++11) | obtains the size of an array (class template specialization) | |
obtains the type of the elements of array (class template specialization) | ||
Functions | ||
(C++11)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++20) | lexicographically compares the values of two array s (function template) | |
(C++11) | specializes the std::swap algorithm (function template) | |
(C++20) | creates a std::array object from a built-in array (function template) | |
(C++11) | 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) | |
(C++14) | 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) |
[edit]Synopsis
// mostly freestanding#include <compare>#include <initializer_list> namespace std {// class template arraytemplate<class T, size_t N>struct array;// partially freestanding template<class T, size_t N>constexprbool 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 algorithmstemplate<class T, size_t N>constexprvoid swap(array<T, N>& x, array<T, N>& y)noexcept(noexcept(x.swap(y))); // array creation functionstemplate<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 interfacetemplate<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>constexprconst T& get(const array<T, N>&)noexcept;template<size_t I, class T, size_t N>constexprconst T&& get(const array<T, N>&&)noexcept;}
[edit]Class template std::array
namespace std {template<class T, size_t N>struct array {// typesusing 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 constexprvoid fill(const T& u);constexprvoid swap(array&)noexcept(is_nothrow_swappable_v<T>); // iteratorsconstexpr iterator begin()noexcept;constexpr const_iterator begin()constnoexcept;constexpr iterator end()noexcept;constexpr const_iterator end()constnoexcept; constexpr reverse_iterator rbegin()noexcept;constexpr const_reverse_iterator rbegin()constnoexcept;constexpr reverse_iterator rend()noexcept;constexpr const_reverse_iterator rend()constnoexcept; constexpr const_iterator cbegin()constnoexcept;constexpr const_iterator cend()constnoexcept;constexpr const_reverse_iterator crbegin()constnoexcept;constexpr const_reverse_iterator crend()constnoexcept; // capacityconstexprbool empty()constnoexcept;constexpr size_type size()constnoexcept;constexpr size_type max_size()constnoexcept; // element accessconstexpr reference operator[](size_type n);constexpr const_reference operator[](size_type n)const;constexpr reference at(size_type n);// freestanding-deletedconstexpr const_reference at(size_type n)const;// freestanding-deletedconstexpr reference front();constexpr const_reference front()const;constexpr reference back();constexpr const_reference back()const; constexpr T* data()noexcept;constexprconst T* data()constnoexcept;}; template<class T, class... U> array(T, U...)-> array<T, 1+ sizeof...(U)>;}