std::set::empty(3)
π NAME π
std::set::empty - std::set::empty, bestie β yes, that's the whole name line, and it's giving βthe function is literally named after what it checks.β This page is std::set::empty(3) from the C++ Standard Libary manual (spelled exactly like that in the header, no cap π).
β¨ Synopsis β¨
Okay so here are the exact signatures, era labels and all β keep that lone (until C++20) line, it's part of the package π:
bool empty() const; (until C++11)
bool empty() const noexcept; (since C++11)
(until C++20)
[[nodiscard]] bool empty() const noexcept; (since C++20)
It checks if the container has no elements, i.e. whether begin() == end().
πΈ Parameters πΈ
(none) β zero parameters, zero stress, it is literally not asking you for anything π«Ά.
π¦ Return value π¦
trueif the container is emptyfalseotherwise
That's it. Iconic behavior, no notes π .
β Complexity β
Constant. Lowkey the easiest complexity reveal ever.
π Example π
The following code uses empty to check if a std::set<int> contains any elements:
// Run this code
#include <iostream>
#include <set>
int main()
{
std::set<int> numbers;
std::cout << std::boolalpha;
std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n';
numbers.insert(42);
numbers.insert(19937);
std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n';
}
Output:
Initially, numbers.empty(): true
After adding elements, numbers.empty(): false
Not the numbers 42 and 19937 doing main character energy in the example πβ¨.
π See also π
sizeβ returns the number of elements (public member function)empty(C++17) β checks whether the container is empty (function template)
mwah π source/version/date sign-off: http://cppreference.com Β· 2024.06.10 Β· std::set::empty(3) β bye bestie, go check those containers π«Άπ
π¦ 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