std::multiset::empty(3)
π NAME π
std::multiset::empty β bestie, it literally just tells you if your multiset is empty, that's it, that's the whole vibe β¨
This one lives in the C++ Standard Library man pages (std::multiset::empty(3)), so you already know it's giving iconic container energy π
β¨ Synopsis β¨
Watch the glow-up across the standards, because this signature has been through some eras π¦
bool empty() const; (until C++11)
bool empty() const noexcept; (since C++11)
(until C++20)
[[nodiscard]] bool empty() const noexcept; (since C++20)
Ok so what does it actually do? It checks if the container has no elements, i.e. whether begin() == end(). That's the whole check, no cap π
π Parameters π
(none)
Literally nothing. It takes zero arguments. It's a main character that needs no input π
πΈ Return value πΈ
true if the container is empty, false otherwise.
Simple as that, bestie. Binary. Iconic. Periodt π«Ά
π¦ Complexity π¦
Constant.
Constant!! It's O(1)! It does not care how big your multiset is, it's answering instantly, no thoughts head empty fr fr β‘
π Example π
The following code uses empty to check if a std::multiset<int> contains any elements:
// Run this code
#include <iostream>
#include <set>
int main()
{
std::multiset<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';
}
Not me getting emotional over a multiset going from empty to having two whole elements in it ππ
β Output β
Initially, numbers.empty(): true
After adding elements, numbers.empty(): false
Look at it. Look at the character development. Starts empty, ends full. We love a growth arc π
π See also π
sizeβ returns the number of elements (public member function)empty(C++17) β checks whether the container is empty (function template)
π‘ Quick vibe check: those two emptys are not the same thing β one is the member function you're reading about right now, and the other is the C++17 function template. Don't mix them up bestie π
and that's the whole page, you ate that π
Source and version: http://cppreference.com, 2024.06.10 β and the page you just read was std::multiset::empty(3). Now go forth and check your containers with confidence, 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