std::multimap::clear(3)
π
std::multimap::clear(3) β bestie edition π
okay so this is the C++ Standard Libary manual page for std::multimap::clear(3), and honestly? Itβs a little icon: the member function that clears out the whole container. main character energy, zero drama. π
π NAME π
std::multimap::clear - std::multimap::clear
yep, the name is the name β self-titled legend behavior. π
β¨ Synopsis β¨
void clear(); (noexcept since C++11)
okay so clear() erases all elements from the container. After this call, size() returns zero. and itβs noexcept since C++11 β slay. π
Heads up, bestie: it invalidates any references, pointers, and iterators referring to contained elements. Any past-the-end iterator remains valid, though β noted and respected. π«Ά
π§Ύ Parameters π§Ύ
(none) β literally no parameters, she takes zero arguments and serves. β¨
π Return value π
(none) β nothing comes back, because the clearing is the whole point. πββοΈ
β±οΈ Complexity β±οΈ
Linear in the size of the container, i.e., the number of elements.
so itβs giving βtouch every element once,β not magic. no cap. πΈ
π§ͺ Example π§ͺ
// Run this code
#include <iostream>
#include <string_view>
#include <map>
void print_info(std::string_view rem, const std::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::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
the before-and-after is honestly so satisfying. πβ¨
π©Ή Defect reports π©Ή
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
LWG 224 - Applied to:
C++98 - Behavior as published: the complexity was
log(size()) + N, butNwas not defined - Correct behavior: corrected to 'linear in size()'
they really said βdefine your terms, bestie,β and honestly? valid. π«Ά
π See also π
eraseβ erases elements (public member function)
π source/version/date: http://cppreference.com, 2024.06.10, std::multimap::clear(3) β mwah, bye 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