std::array<T,N>::fill

From cppreference.com
< cpp‎ | container‎ | array
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.

Parameters

value - the value to assign to the elements

Return value

(none)

Complexity

Linear in the size of the container.

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:

▄▀▄▀▄▀▄▀
▄▀▄▀▄▀▄▀
▄▀▄▀▄▀▄▀
▄▀▄▀▄▀▄▀

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)