std::flat_set::clear(3)
π std::flat_set::clear π
okay so welcome to the std::flat_set::clear(3) page β manual name folded in right here: it's from the C++ Standard Libary manual. (Yes, that spelling is what the header says; we're keeping it exactly, bestie.) This is the std::flat_set clear page and it is lowkey iconic: one tiny member, zero drama. π«Ά
πΈ NAME πΈ
std::flat_set::clear β std::flat_set::clear. That's the name, no cap. π
β¨ Synopsis β¨
void clear() noexcept; (since C++23)
It erases all elements from the container adaptor. After this call, size() returns zero. Fr fr, that's the whole plot. π
π¨ Important vibe check: it invalidates any references, pointers, and iterators referring to contained elements. So don't be out here using old refs after the clear, bestie β they are not giving valid anymore. π
π Parameters π
(none)β no parameters, not even one. π
π¦ Return value π¦
(none)β nothing comes back. It's giving void and unbothered. π
π₯ Complexity π₯
Linear in the size of the container adaptor, i.e., the number of elements. So yeah, it scales with how much stuff is in there. π
π Example π
Okay so run this code, it's literally the whole before/after glow-up π
// Run this code
#include <iostream>
#include <string_view>
#include <flat_set>
void print_info(std::string_view rem, const std::flat_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::flat_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
π See also π
eraseβ erases elements, and it's a public member function. That's the other icon, go check it out. π
Source/version/date sign-off: http://cppreference.com Β· 2024.06.10 Β· std::flat_set::clear(3). That's the footer info, folded into this cute little send-off instead of a boring last line. 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