std::array<T,N>:: fill
From cppreference.net
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::array
| Member types | ||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||
| Helper classes | ||||||||||||||||||||||||||
| Deduction guides (C++17) | ||||||||||||||||||||||||||
|
void
fill
(
const
T
&
value
)
;
|
(C++11以降)
(constexprはC++20以降) |
|
コンテナ内のすべての要素に value を割り当てます。
目次 |
パラメータ
| value | - | 要素に割り当てる値 |
戻り値
(なし)
計算量
コンテナのサイズに対して線形。
例
このコードを実行
#include <array> #include <cstddef> #include <iostream> int main() { constexpr std::size_t xy = 4; using Cell = std::array<unsigned char, 8>; std::array<Cell, xy * xy> board; board.fill({0xE2, 0x96, 0x84, 0xE2, 0x96, 0x80, 0, 0}); // "▄▀"; for (std::size_t count{}; Cell c : board) std::cout << c.data() << ((++count % xy) ? "" : "\n"); }
出力例:
▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀
関連項目
|
指定された値を範囲内のすべての要素にコピー代入する
(関数テンプレート) |
|
|
指定された値を範囲内のN個の要素にコピー代入する
(関数テンプレート) |
|
|
(C++20)
|
範囲の要素に特定の値を代入する
(アルゴリズム関数オブジェクト) |