std::array
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Defined in header <array>
|
||
template< class T, |
(C + + 11以来) | |
std::array
は固定サイズの配列をカプセル化するコンテナです.
この構造体は Cスタイルの配列と同様のセマンティクスを持ちます.
array<T,N> のサイズと効率は、Cスタイルの配列T[N]
のサイズと効率と等価です.この構造体は、自身のサイズの把握、代入サポート、ランダムアクセス・イテレータなどといった標準コンテナの利点を提供します。
ゼロの長さの配列のための特殊ケースがあります (N == 0
).このケースでは、 array.begin() == array.end() となり, その値はユニークな値になります.
サイズ0のarrayに対するfront() と back() の呼び出しは未定義です。
array
is an aggregate (it has no constructors and no private or protected members), which allows it to use aggregate-initialization.
An array can also be used as a tuple of N
elements of the same type.
[編集] メンバータイプ
メンバー·タイプ
Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
value_type
|
T
|
size_type
|
size_t |
difference_type
|
ptrdiff_t |
reference
|
value_type&
|
const_reference
|
const value_type&
|
pointer
|
T*
|
const_pointer
|
const T*
|
iterator
|
RandomAccessIterator
|
const_iterator
|
一定のランダムアクセス反復子を返します
Original: Constant random access iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
reverse_iterator
|
std::reverse_iterator<iterator> |
const_reverse_iterator
|
std::reverse_iterator<const_iterator> |
[編集] メンバ関数
Original: Element access The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
指定された要素にアクセスします。境界チェックを行います。 (パブリックメンバ関数) | |
指定された要素にアクセスします Original: access specified element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
最初の要素にアクセスします Original: access the first element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
末尾の要素にアクセスします (パブリックメンバ関数) | |
(C++11) |
基になる配列へのアクセスを指示する Original: direct access to the underlying array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) |
Original: Iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
先頭を指すイテレータを返します (パブリックメンバ関数) | |
末尾を指すイテレータを返す Original: returns an iterator to the end The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
逆イテレータの先頭を返します (パブリックメンバ関数) | |
逆イテレータの末尾を返します (パブリックメンバ関数) | |
Original: Capacity The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
コンテナが空であるかどうかをチェックします (パブリックメンバ関数) | |
要素数を返します Original: returns the number of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
要素の最大数を返します Original: returns the maximum possible number of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
Original: Operations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
指定された値で容器を満たす Original: fill the container with specified value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
コンテナの内容をスワップします (パブリックメンバ関数) |
[編集] 非メンバ関数
辞書的にarray内の値を比較します Original: lexicographically compares the values in the array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) | |
accesses an element of an array (関数テンプレート) | |
特殊化されたstd::swapアルゴリズム (関数テンプレート) |
[編集] ヘルパークラス
array のサイズを取得します Original: obtains the size of an array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) | |
array の要素の型を取得します Original: obtains the type of the elements of array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) |
[編集] 例
#include <string> #include <iterator> #include <iostream> #include <algorithm> #include <array> int main() { // construction uses aggregate initialization std::array<int, 3> a1{ {1,2,3} }; // double-braces required std::array<int, 3> a2 = {1, 2, 3}; // except after = std::array<std::string, 2> a3 = { {std::string("a"), "b"} }; // container operations are supported std::sort(a1.begin(), a1.end()); std::reverse_copy(a2.begin(), a2.end(), std::ostream_iterator<int>(std::cout, " ")); // ranged for loop is supported for(auto& s: a3) std::cout << s << ' '; }
Output:
3 2 1 a b