std::array::fill(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 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