std::map::empty(3)
β¨ std::map::empty(3) β¨
okay so welcome to the std::map::empty(3) page from the C++ Standard Libary manual β yes bestie, we're checking whether a std::map is empty, and this is literally the whole vibe.
πΈ NAME πΈ
std::map::empty - std::map::empty β that's the name, no cap.
πΈ SYNOPSIS πΈ
here are the signature glow-ups, and yes the until / since labels matter:
bool empty() const; (until C++11)
bool empty() const noexcept; (since C++11)
(until C++20)
[[nodiscard]] bool empty() const noexcept; (since C++20)
Checks if the container has no elements, i.e. whether begin() == end().
π PARAMETERS π
none β literally no parameters. she takes nothing.
π RETURN VALUE π
true if the container is empty, false otherwise.
π¦ COMPLEXITY π¦
Constant.
β¨ EXAMPLE β¨
the following code uses empty to check if a std::map<int, int> contains any elements:
Run this code:
#include <iostream>
#include <map>
#include <utility>
int main()
{
std::map<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';
}
π OUTPUT π
Initially, numbers.empty(): true
After adding elements, numbers.empty(): false
π SEE ALSO π
sizeβ returns the number of elements (public member function).emptyβ checks whether the container is empty (C++17) (function template).
xoxo, your Unix bestie π β source/version: http://cppreference.com; date: 2024.06.10.
π¦ 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