std::unorde...iset::clear(3)
πΈ NAME πΈ
std::unordered_multiset::clear β the member function that wipes every element out of your unordered multiset. This is the std::unorde...iset::clear(3) page from the C++ Standard Libary manual, and yes bestie, thatβs literally how the manual name is spelled up top. No cap.
β¨ Synopsis β¨
void clear() noexcept;
Available since C++11. Itβs giving βone call and the whole container is goneβ energy.
Okay so hereβs the tea: it erases all elements from the container. After this call, size() returns zero. Literally zero. Empty. Nothing left. π
Heads up, bestie: it invalidates any references, pointers, and iterators referring to contained elements. It may also invalidate past-the-end iterators. So donβt be out here using stale iterators after the clear β thatβs not the vibe.
π Parameters π
- (none) β no parameters, fr fr. It takes nothing.
π Return value π
- (none) β it returns nothing. Not even a little guy. Not even a vibe check.
π₯ Complexity π₯
Linear in the size of the container, i.e., the number of elements.
π Example π
// Run this code
#include <iostream>
#include <string_view>
#include <unordered_set>
void print_info(std::string_view rem, const
std::unordered_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::unordered_multiset<int> container{1, 2, 3};
print_info("Before clear: ", container);
container.clear();
print_info("After clear: ", container);
}
π Possible output π
Before clear: { 1 2 3 }
Size=3
After clear: { }
Size=0
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards:
- DR
LWG 2550β Applied to:C++11- Behavior as published: for unordered associative containers, unclear if complexity is linear in the number of elements or buckets
- Correct behavior: clarified that itβs linear in the number of elements
π See also π
eraseβ erases elements (public member function)
xoxo, your local C++ bestie π β source/version and date: http://cppreference.com, 2024.06.10, page std::unorde...iset::clear(3). Periodt. π«Ά
π¦ 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