std::flat_multimap::clear(3)

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

okay so bestie, welcome to the std::flat_multimap::clear(3) page from the C++ Standard Libary πŸ’– this one is short and sweet: it's the glow-up that wipes your whole flat_multimap clean ✨

πŸŽ€ NAME πŸŽ€

std::flat_multimap::clear β€” std::flat_multimap::clear (yes bestie, the name is literally the name, iconic behavior πŸ’…)

🌸 Synopsis 🌸

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

Erases all elements from the container adaptor. After this call, size() returns zero.

Invalidates any references, pointers, and iterators referring to contained elements. 🫢

πŸ¦‹ Parameters πŸ¦‹

  • (none) β€” not a single parameter, she takes zero arguments, periodt πŸ’€

πŸ“ Return value πŸ“

  • (none) β€” nothing comes back, she just clears and leaves ✨

πŸ”₯ Complexity πŸ”₯

Linear in the size of the container adaptor, i.e., the number of elements. So yeah, she's doing actual work in there, no cap πŸ’…

πŸ’œ Example πŸ’œ

// Run this code

#include <iostream>
#include <string_view>
#include <flat_map>

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

int main()
{
    std::flat_multimap<int, char> container{{1, 'x'}, {2, 'y'}, {3, 'z'}};
    print_info("Before clear: ", container);
    container.clear();
    print_info("After clear: ", container);
}

πŸ“€ Output πŸ“€

Before clear: { [1]:x [2]:y [3]:z }
Size=3
After clear: { }
Size=0

🌈 See also 🌈

  • erase β€” erases elements (public member function)

mwah πŸ’‹ this cutie came from http://cppreference.com, version/date 2024.06.10, and it's the std::flat_multimap::clear(3) page. byeee πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from