std::queue::empty(3)

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

πŸ’– NAME πŸ’–

You're on the std::queue::empty(3) page in the C++ Standard Libary, bestie. The name is std::queue::empty β€” and the one-liner? Also std::queue::empty. No cap, that's the whole name section. Iconic.

πŸ¦‹ Synopsis πŸ¦‹

Two eras, two signatures, same "is it empty tho" energy:

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

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

πŸ“ Parameters πŸ“

  • (none) β€” literally no parameters. Not a single one. The parameter list is giving empty-queue energy.

🌈 Return value 🌈

  • true if the underlying container is empty.
  • false otherwise.

🧚 Complexity 🧚

Constant. That's the whole complexity note, bestie.

πŸ”₯ Example πŸ”₯

       // Run this code

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

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

            std::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).

That's the whole page, bestie. Source/version/date: http://cppreference.com, 2024.06.10, std::queue::empty(3). Slay. πŸ’…

πŸ“¦ where this page comes from