std::deque::empty(3)

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

std::deque::empty(3)

okay bestie, this is from the C++ Standard Libary manual, and we're talking about std::deque::empty β€” the tiny little β€œis my deque empty?” check. No cap, it’s a whole mood. ✨

πŸ’– NAME πŸ’–

std::deque::empty β€” std::deque::empty

yep, that’s the whole name. Short, iconic, to the point. πŸŽ€

✨ Synopsis ✨

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().

The version tags are literally part of the synopsis, bestie β€” (until C++11), (since C++11), (until C++20), and (since C++20) are all doing their own little era-defining thing. πŸ’…

πŸ™ˆ Parameters πŸ™ˆ

(none) β€” zero arguments. Not a single one. It’s giving low-maintenance. 🫢

🌈 Return value 🌈

true if the container is empty, false otherwise.

⭐ Complexity ⭐

Constant.

πŸ“ Example πŸ“

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

// Run this code

#include <deque>
#include <iostream>

int main()
{
    std::deque<int> numbers;
    std::cout << std::boolalpha;
    std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n';

    numbers.push_back(42);
    numbers.push_back(13317);
    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, page dated 2024.06.10, title std::deque::empty(3) β€” catch u later bestie 🫢

πŸ“¦ where this page comes from