std::flat_multimap::empty(3)
π std::flat_multimap::empty(3) β C++ Standard Library, bestie edition
okay so real talk, this page is from the C++ Standard Library manual (section 3, bestie, we're in the big leagues β¨) and it's literally about one tiny little function that answers one tiny little question: is my flat_multimap empty or not? that's it. that's the whole vibe check. π«Ά
πΈ NAME πΈ
std::flat_multimap::empty β and yes bestie, the name of the function is literally std::flat_multimap::empty, no notes, iconic behavior, it does exactly what it says on the tin π
β¨ Synopsis β¨
here's the signature, copy it exactly, do not freestyle it:
[[nodiscard]] bool empty() const noexcept; (since C++23)
so what does it do? it checks if the underlying containers have no elements. like, zero. nada. empty empty. π³οΈ
and it's equivalent to this:
return begin()
== end();
(yeah the original page line-wraps it like that, it's giving "my code got squished by the terminal" energy π but that's the equivalence: return begin() == end();)
also note that [[nodiscard]] β the compiler will side-eye you HARD if you call this and just throw away the answer. don't do that. it's rude. π
π Parameters π
(none)
zero parameters. no args, no drama, she takes nothing and she gives everything. π
π¦ Return value π¦
trueif the underlying containers are emptyfalseotherwise
that's it. binary. black and white. no nuance, no "it depends", no <italic>maybe</italic>. π
π Complexity π
Constant. β‘
like, instant. no loops, no scanning, no "let me think about it". just vibes and a comparison. ate and left no crumbs. π₯
π Example π
the original page says: the following code uses empty to check if a std::flat_multimap<int, int> contains any elements. and honestly? great use of the function, 10/10, no notes.
// Run this code
#include <iostream>
#include <flat_map>
#include <utility>
int main()
{
std::flat_multimap<int,int> numbers;
std::cout << std::boolalpha;
std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n';
numbers.emplace(42, 13);
numbers.insert(std::make_pair(13317, 123));
std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n';
}
bestie look at those numbers though β 42, 13, 13317, 123 β someone was having fun in the test suite and i respect it ππ
and notice the std::boolalpha β that's the little sprinkle that makes true/false print as actual words instead of 1/0. we love a readable output. β¨
π§ Output π§
Initially, numbers.empty(): true
After adding elements, numbers.empty(): false
she starts empty, she gets some elements shoved in via emplace and insert, and then she's not empty anymore. character development. π
π See also π
sizeβ returns the number of elements (public member function)emptyβ checks whether the container is empty (C++17) (function template)
iykyk, size is the "how many" girlie and empty is the "any at all?" girlie. two different questions, both valid, both slaying. π
ngl if you're callingempty()and then immediately callingsize()to check if it's0... bestie. that's the same question twice. pick a lane. π«Ά
and that's the page!! source is cppreference.com, dated 2024.06.10 β go drink some water, go compile something with -std=c++23, and remember: [[nodiscard]] is not a suggestion, it's a lifestyle. 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