标准库头文件 <array>
来自cppreference.com
此头文件是容器库的一部分。
包含 | ||
<initializer_list>(C++11) | ||
类 | ||
(C++11 起) |
静态的相接数组 (类模板) | |
获得array 的大小 (类模板特化) | ||
获得array 元素的类型 (类模板特化) | ||
函数 | ||
按照字典顺序比较 array 中的值 (函数模板) | ||
访问array 的一个元素 (函数模板) | ||
(C++11) |
特化 std::swap 算法 (函数模板) |
[编辑] 概要
#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> 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; }
[编辑] 类 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]; // 仅为说明 // 对于聚合类型无显式的构造/复制/销毁 void fill(const T& u); void swap(array<T, N>&) noexcept(is_nothrow_swappable_v<T>); // 迭代器: 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() noexcept; constexpr const_iterator cend() noexcept; constexpr const_reverse_iterator crbegin() const noexcept; constexpr const_reverse_iterator crend() const noexcept; // 容量: constexpr size_type size() noexcept; constexpr size_type max_size() noexcept; constexpr bool empty() noexcept; // 元素访问 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)>;
[编辑] 注意
变量 array::elems
仅为说明,它不是接口的一部分。