std::set::clear(3)
π std::set::clear(3) π
okay bestie, welcome to std::set::clear(3) from the C++ Standard Libary manual β yes, βLibaryβ is literally in the header, and we are respecting the artifact π.
πΈ NAME πΈ
std::set::clear - std::set::clear
thatβs the NAME section and honestly it ate. no notes. π
π¦ Synopsis π¦
void clear(); (noexcept since C++11)
so hereβs the tea: she erases all elements from the container. after this call, size() returns zero. iconic behavior, fr fr β¨.
she invalidates any references, pointers, and iterators referring to contained elements. but β and this is important β any past-the-end iterator remains valid π«Ά.
πΈ Parameters πΈ
(none)
no parameters, no drama. she takes nothing and still clears the whole vibe check π.
π Return value π
(none)
returns nothing. she gives no return value, only closure. π
π₯ Complexity π₯
Linear in the size of the container, i.e., the number of elements.
thatβs the whole complexity tea. periodt. β
β¨ Example β¨
// Run this code
#include <iostream>
#include <string_view>
#include <set>
void print_info(std::string_view rem, const std::set<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::set<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
she really said βempty set, empty set, empty setβ and the output ATE. π
π 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 waslog(size()) + N, butNwas not defined; Correct behavior: corrected to'linear in size()'.
history was made, paperwork was filed, and the complexity got corrected. π
π See also π
eraseβ erases elements (public member function)
like, if clear() is the full reset, erase is the pick-and-choose girlypop. π¦
kisses bestie, this page is from http://cppreference.com, dated 2024.06.10, and itβs literally titled std::set::clear(3). bye and slay πβ¨
π¦ 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