名稱空間
變體
操作

標準庫標頭檔案 <array> (C++11)

來自 cppreference.com
 
 
標準庫標頭檔案
通用工具
<any> (C++17)
<bitset>
<bit> (C++20)
<charconv> (C++17)
<expected> (C++23)
<format> (C++20)
<functional>
<optional> (C++17)
<tuple> (C++11)
<typeindex> (C++11)
<utility>
<variant> (C++17)
容器
<array> (C++11)
<deque>
<flat_map> (C++23)
<flat_set> (C++23)
<forward_list> (C++11)
<hive> (C++26)
<inplace_vector> (C++26)   
<list>
<map>
<mdspan> (C++23)
<queue>
<set>
<span> (C++20)
<stack>
<unordered_map> (C++11)
<unordered_set> (C++11)
<vector>
迭代器
<iterator>
Ranges
<generator> (C++23)
<ranges> (C++20)
演算法
<algorithm>
<numeric>
字串
<cctype>
<cstring>
<cuchar> (C++11)
<cwchar>
<cwctype>
<string_view> (C++17)
<string>
文字處理
<clocale>
<codecvt> (C++11/17/26*)
<locale>
<regex> (C++11)
<text_encoding> (C++26)   
數值
<cfenv> (C++11)
<cmath>
<complex>
<linalg> (C++26)
<numbers> (C++20)
<random> (C++11)
<simd> (C++26)
<valarray>
時間
<chrono> (C++11)
<ctime>
C 相容性
<ccomplex> (C++11/17/20*)
<ciso646> (直到 C++20)
<cstdalign> (C++11/17/20*)
<cstdbool> (C++11/17/20*)
<ctgmath> (C++11/17/20*)
 

此標頭檔案是 容器 庫的一部分。

目錄

包含

(C++20)
三路比較運算子支援[編輯]
std::initializer_list 類模板[編輯]

(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 的值
(函式模板) [編輯]
特化 std::swap 演算法
(函式模板) [編輯]
(C++20)
從一個內建陣列建立一個 std::array 物件
(函式模板) [編輯]
訪問 array 的一個元素
(函式模板) [編輯]
範圍訪問
(C++11)(C++14)
返回指向容器或陣列開頭的迭代器
(函式模板) [編輯]
(C++11)(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)>;
}