std::flat_map::clear(3)

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

πŸ’… NAME

std::flat_map::clear β€” literally the page for std::flat_map::clear, bestie. You’re reading the std::flat_map::clear(3) page from the C++ Standard Libary manual. πŸ’–


✨ Synopsis

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

Okay so clear() erases all elements from the container adaptor. After this call, size() returns zero. It also invalidates any references, pointers, and iterators referring to contained elements. πŸ’…

πŸŽ€ Parameters

(none) β€” not a single parameter, bestie. 🫢

πŸ’– Return value

(none) β€” it returns nothing, periodt. 😭

πŸ”₯ Complexity

Linear in the size of the container adaptor, i.e., the number of elements. So it’s giving β€œdepends on how many elements are in there.” ⭐

🌸 Example

// Run this code

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

void print_info(std::string_view rem, const std::flat_map<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_map<int, char> container{{1, 'x'}, {2, 'y'}, {3, 'z'}};
    print_info("Before clear: ", container);
    container.clear();
    print_info("After clear: ", container);
}

πŸ¦‹ Output

It prints exactly this, no cap:

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

πŸ‘‘ See also

  • erase β€” erases elements (public member function). πŸ‘‘

Mwah πŸ’‹ β€” source: http://cppreference.com, version/date: 2024.06.10, page: std::flat_map::clear(3). Stay clear, bestie! 🫢✨

πŸ“¦ where this page comes from