std::flat_set::clear(3)

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

πŸ’… std::flat_set::clear πŸ’…

okay so welcome to the std::flat_set::clear(3) page β€” manual name folded in right here: it's from the C++ Standard Libary manual. (Yes, that spelling is what the header says; we're keeping it exactly, bestie.) This is the std::flat_set clear page and it is lowkey iconic: one tiny member, zero drama. 🫢

🌸 NAME 🌸

std::flat_set::clear β€” std::flat_set::clear. That's the name, no cap. πŸŽ€

✨ Synopsis ✨

void clear() noexcept;  (since C++23)

It erases all elements from the container adaptor. After this call, size() returns zero. Fr fr, that's the whole plot. πŸ’…

🚨 Important vibe check: it invalidates any references, pointers, and iterators referring to contained elements. So don't be out here using old refs after the clear, bestie β€” they are not giving valid anymore. 😭

πŸŽ€ Parameters πŸŽ€

  • (none) β€” no parameters, not even one. πŸ“

πŸ¦‹ Return value πŸ¦‹

  • (none) β€” nothing comes back. It's giving void and unbothered. πŸ’œ

πŸ”₯ Complexity πŸ”₯

Linear in the size of the container adaptor, i.e., the number of elements. So yeah, it scales with how much stuff is in there. πŸ‘‘

🌈 Example 🌈

Okay so run this code, it's literally the whole before/after glow-up πŸ‘‡

// Run this code

#include <iostream>
#include <string_view>
#include <flat_set>

void print_info(std::string_view rem, const std::flat_set<int>& v)
{
    std::cout << rem << "{ ";
    for (const auto& value : v)
        std::cout << value << ' ';
    std::cout << "}\n";
    std::cout << "Size=" << v.size() << '\n';
}

int main()
{
    std::flat_set<int> container{1, 2, 3};
    print_info("Before clear: ", container);
    container.clear();
    print_info("After clear: ", container);
}

⭐ Output ⭐

Before clear: { 1 2 3 }
Size=3
After clear: { }
Size=0

πŸ‘‘ See also πŸ‘‘

  • erase β€” erases elements, and it's a public member function. That's the other icon, go check it out. πŸŽ€

Source/version/date sign-off: http://cppreference.com Β· 2024.06.10 Β· std::flat_set::clear(3). That's the footer info, folded into this cute little send-off instead of a boring last line. Mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from