Namespaces
Variants
Actions

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

From cppreference.com
< cpp‎ | container‎ | array
 
C++
 
Containers library
 
std::array
void fill( const T& value );
(since C++11)
(constexpr since C++20)

Assigns the 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 <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}); / "▄▀";
 
    for (std::size_t count{}; Cell c : board)
        std::cout << c.data() << ((++count % xy) ? "" : "\n");
}

Possible output:

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

[edit] See also

copy-assigns the given value to every element in a range
(function template) [edit]
copy-assigns the given value to N elements in a range
(function template) [edit]
assigns a range of elements a certain value
(algorithm function object)[edit]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant