std::array::fill(3)
πΈ NAME πΈ
okay so bestie, you're on the std::array::fill(3) page from the C++ Standard Libary β yes, that's the manual name, and yes it's spelled like that, we move π
.
std::array::fill β std::array::fill. That's it. That's the name. Minimal, iconic, no notes π
β¨ Synopsis β¨
Here's the signature, copied exactly, no cap:
void fill( const T& value ); (since C++11)
(constexpr since C++20)
What it does: assigns the value to all elements in the container. That's the whole vibe β it's giving "fill every slot, leave no element behind" β¨.
π Parameters π
valueβ the value to assign to the elements. One parameter, one job, and she's doing it π«Ά.
π Return value π
(none). Nothing. Nada. It's not returning anything, bestie β it just does the fill and dips π.
π¦ Complexity π¦
Linear in the size of the container. Big container = more steps, small container = quick lil slay, but it's linear either way, periodt π .
π Example π
Run this code, bestie β it's the exact example from the page:
// 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 β
ββββββββ
ββββββββ
ββββββββ
ββββββββ
π See also π
fillβ copy-assigns the given value to every element in a range (function template)fill_nβ copy-assigns the given value to N elements in a range (function template)ranges::fill(C++20) β assigns a range of elements a certain value (niebloid)
okay bestie, that's the page π this lil rewrite was served from http://cppreference.com, version/date 2024.06.10, and the page is std::array::fill(3). periodt π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms