std::unorde...iset::empty(3)
π std::unordered_multiset::empty
okay bestie, welcome to the <unordered_set> glow-up page π this one lives in the C++ Standard Library and the star of the show is std::unordered_multiset::empty β yes the name is literally the same as the page title, we love a self-titled icon β¨
β¨ SYNOPSIS β¨
bool empty() const noexcept; (since C++11)
(until C++20)
[[nodiscard]] bool empty() const noexcept; (since C++20)
so basically it checks if the container has no elements, i.e. whether begin() == end() π like, is your multiset giving empty-girl energy or not, that's the whole vibe check.
heads up: since C++20 it's got [[nodiscard]] on it β meaning if you call it and then just ignore the result, the compiler is gonna side-eye you π don't do that, use the answer.
πΈ PARAMETERS πΈ
(none) β not a single argument, she takes zero notes, zero input, purely vibes π«Ά
β RETURN VALUE β
trueif the container is empty πfalseotherwise π
π¦ COMPLEXITY π¦
Constant. β as in, O(1), instant, no scrolling required, iconic behavior π
π EXAMPLE π
the following code uses empty to check if a std::unordered_multiset<int> contains any elements:
// Run this code
#include <iostream>
#include <unordered_set>
int main()
{
std::unordered_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';
}
π Output
Initially, numbers.empty(): true
After adding elements, numbers.empty(): false
see how it flipped from true to false once we inserted 42 and 19937?? the way that she just knows ππ₯ main character energy fr fr.
π SEE ALSO
sizeβ returns the number of elements (public member function π§)empty(C++17) β checks whether the container is empty (function template β¨)
and that's the whole page bestie, no cap, every last detail accounted for π
source/version + date: this lil masterpiece comes from http://cppreference.com, version 2024.06.10 β mwah, catch you on the next manpage π«Άππ
π¦ 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