std::flat_map::clear(3)
π 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
- 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