std::array<T,N>::fill
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Containers library
(C++17)
(C++11)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++23)
(C++23)
(C++20)
(C++23)
Tables
std::array
array::fill
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)
Deduction guides (C++17)
void fill( const T& value );
(since C++11) (constexpr since C++20)
Assigns the value to all elements in the container.
[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
Run this code
#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"); }
Possible output:
▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀