std::array<T,N>::fill
| void fill( const T& value ); |
(since C++11) (until C++20) |
|
| constexpr void fill( const T& value ); |
(since C++20) | |
Assigns the given value value to all elements in the container.
Contents |
[edit] Parameters
| value | - | the value to assign to the elements |
[edit] Return value
(none)
[edit] Complexity
Linear in the size of the container.
[edit] Example
#include <array> #include <iostream> #include <algorithm> int main() { constexpr int 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} }); // "▄▀"; std::for_each(board.cbegin(), board.cend(), [xy, O=1](const auto& c) mutable { std::cout << c.data() << ((O++ % xy) ? "" : "\n"); }); }
Output:
▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀
[edit] See also
| copy-assigns the given value to every element in a range (function template) | |
| copy-assigns the given value to N elements in a range (function template) |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
