std::unorde...imap::empty(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

okay bestie, welcome to the std::unordered_multimap::empty(3) page πŸ’… the header is std::unorde...imap::empty(3) and the manual name is C++ Standard Libary β€” yes, that spelling, we're keeping it 🫢

Name line energy: std::unordered_multimap::empty - std::unordered_multimap::empty. It's the member function that checks whether your std::unordered_multimap has no elements. That's the whole name, and it's serving exactly what it says ✨


πŸ¦‹ Synopsis πŸ¦‹

Okay so here's the signature tea, bestie:

bool empty() const noexcept;                (since C++11)
                                            (until C++20)
[[nodiscard]] bool empty() const noexcept;  (since C++20)

The plain bool empty() const noexcept; form is (since C++11) and (until C++20). The [[nodiscard]] bool empty() const noexcept; form is (since C++20). Both are const noexcept, and the [[nodiscard]] is right there in the signature πŸ‘‘

This is literally the checks line: it checks if the container has no elements, i.e. whether begin() == end() 🌈

πŸŽ€ Parameters πŸŽ€

Parameters: (none). That's the whole section, bestie. Zero params, no drama, no little argument side quests πŸ™ˆ

πŸ’– Return value πŸ’–

true if the container is empty, false otherwise. That's it β€” boolean main character energy ⭐

πŸ”₯ Complexity πŸ”₯

Constant. That's the entire complexity section. Constant. No cap, fr fr πŸ’€

πŸ¦‹ Example πŸ¦‹

The following code uses empty to check if a std::unordered_multimap<int, int> contains any elements:

// Run this code

#include <iostream>
#include <unordered_map>
#include <utility>

int main()
{
    std::unordered_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';
}

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)

made with πŸ’– from http://cppreference.com Β· version/date 2024.06.10 Β· page std::unorde...imap::empty(3) 🫢

πŸ“¦ where this page comes from