std::flat_multiset::clear(3)
π std::flat_multiset::clear
okay bestie so this is the clear member of std::flat_multiset from the C++ Standard Library β yes, the whole std situation, we're in C++ Standard Libary territory (their spelling, not mine, iykyk π«Ά). It's giving "make it empty, make it iconic."
β¨ Synopsis β¨
void clear() noexcept; (since C++23)
So like, clear() is a thing since C++23, and it's noexcept β meaning it will not be throwing hands. Ever. Periodt.
What it does: it erases all elements from the container adaptor. Every single one. Gone. After this call, size() returns zero β empty, fresh, brand new era π
.
π¨ real talk though: it invalidates any references, pointers, and iterators referring to contained elements. All of them. They're not coming back, bestie β do not use them after this, fr fr π.
π Parameters π
(none) β literally nothing, no arguments, she takes zero input, highkey low-maintenance π¦
πΈ Return value πΈ
(none) β she gives you nothing back, because she already gave you everything (an empty container) π
β Complexity β
Linear in the size of the container adaptor, i.e., the number of elements. So the more stuff you got in there, the more work it does β no cap, it's proportional π
π₯ Example π₯
// Run this code
#include <iostream>
#include <string_view>
#include <flat_set>
void print_info(std::string_view rem, const std::flat_multiset<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_multiset<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
the way the size just goes from 3 to 0β¦ she ate and left no crumbs πβ¨
π See also π
eraseβ erases elements (public member function) β likeclearbut she's picky about which ones π
so yeah, that's the whole vibe. go forth and empty your containers, bestie π§π
this lil page is courtesy ofhttp://cppreference.com, dated2024.06.10βstd::flat_multiset::clear(3), mwah π
π¦ 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