std::priority_queue::empty(3)

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

πŸ’– NAME πŸ’–

okay so welcome to std::priority_queue::empty(3) from the C++ Standard Libary manual β€” yes, β€œLibary” is the manual’s spelling and we’re not touching it, periodt πŸ’…. The name up top is std::priority_queue::empty - std::priority_queue::empty, which is giving self-referential main character energy, and honestly? iconic ✨.

πŸ¦‹ Synopsis πŸ¦‹

two signatures, depending on which C++ era you’re living in:

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

Checks if the underlying container has no elements. Equivalent to return c.empty();.

🌸 Parameters 🌸

(none) β€” literally zero parameters, she takes nothing, low maintenance queen 🫢.

πŸ’œ Return value πŸ’œ

true if the underlying container is empty, false otherwise. That’s the whole return vibe, no cap ✨.

⭐ Complexity ⭐

Constant. periodt.

πŸ“ Example πŸ“

// Run this code β€” go off, bestie:

#include <algorithm>
#include <iostream>
#include <queue>

int main()
{
    std::cout << std::boolalpha;

    std::priority_queue<int> queue;

    std::cout << "Initially, queue.empty(): " << queue.empty() << '\n';

    queue.push(42);
    std::cout << "After adding elements, queue.empty(): " <<
       queue.empty() << '\n';
}

πŸŽ€ Output πŸŽ€

Initially, queue.empty(): true
After adding elements, queue.empty(): false

🌈 See also 🌈

  • size β€” returns the number of elements (public member function)
  • empty β€” checks whether the container is empty (C++17) (function template)

source/version/date check, bestie: http://cppreference.com, 2024.06.10, page std::priority_queue::empty(3) β€” mwah, bye πŸ’‹πŸ’–

πŸ“¦ where this page comes from