std::stack::empty(3)

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

πŸ’– std::stack::empty(3) πŸ’–

okay so welcome to the std::stack::empty(3) page from the C++ Standard Libary manual β€” yes bestie, that spelling is exactly what the header says, and we’re keeping it.


πŸ’… NAME πŸ’…

std::stack::empty - std::stack::empty

(Yes, the name is the name. Iconic behavior. πŸŽ€)

✨ Synopsis ✨

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 none, bestie. no arguments, no stress. πŸ’…

🌸 Return value 🌸

true if the underlying container is empty, false otherwise. fr fr.

πŸ¦‹ Complexity πŸ¦‹

Constant. that’s the whole vibe. ✨

πŸ”₯ Example πŸ”₯

       // Run this code

        #include <algorithm>
        #include <iostream>
        #include <stack>

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

            std::stack<int> stack;

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

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

🌈 Output 🌈

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

πŸ‘‘ See also πŸ‘‘

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

πŸ’– cute sign-off: source/version is http://cppreference.com, and the date is 2024.06.10. periodt. 🫢

πŸ“¦ where this page comes from