标准库头文件 <array> (C++11)
来自 cppreference.com
此头文件是 容器 库的一部分。
包含 | ||
(C++20) |
三路比较运算符 支持 | |
(C++11) |
std::initializer_list 类模板 | |
类 | ||
(C++11) |
固定大小的原地连续数组 (类模板) | |
(C++11) |
获取元组类型元素的个数 (类模板) | |
(C++11) |
获取元组类型元素的类型 (类模板) | |
(C++11) |
获取array 的大小(类模板特化) | |
获取array 元素的类型(类模板特化) | ||
函数 | ||
(C++11)(C++11)(C++20中移除)(C++11)(C++20中移除)(C++11)(C++20中移除)(C++11)(C++20中移除)(C++11)(C++20中移除)(C++20) |
字典序比较两个array 的值(函数模板) | |
(C++11) |
特化std::swap 算法 (函数模板) | |
(C++20) |
从内置数组创建std::array 对象(函数模板) | |
(C++11) |
访问array 的元素(函数模板) | |
范围访问 | ||
(C++11)(C++14) |
返回指向容器或数组开头的迭代器 (函数模板) | |
(C++11)(C++14) |
返回指向容器或数组末尾的迭代器 (函数模板) | |
(C++14) |
返回指向容器或数组开头的反向迭代器 (函数模板) | |
(C++14) |
返回容器或数组的反向末尾迭代器 (函数模板) | |
(C++17)(C++20) |
返回容器或数组的大小 (函数模板) | |
(C++17) |
检查容器是否为空 (函数模板) | |
(C++17) |
获取指向底层数组的指针 (函数模板) |
[编辑] 概要
// mostly freestanding #include <compare> #include <initializer_list> namespace std { // class template array template<class T, size_t N> struct array; // partially freestanding 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; }
[编辑] 类模板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 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); // freestanding-deleted constexpr const_reference at(size_type n) const; // freestanding-deleted 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)>; }