std::array<T,N>:: fill
From ja.cppreference.net
|
void
fill
(
const
T
&
value
)
;
|
(C++11以降)
(constexprはC++20以降) |
|
コンテナ内のすべての要素に 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"); } 出力例: ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ 関連項目
|