std::list::empty(3)

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

🌸 NAME 🌸

okay so bestie, welcome to std::list::empty(3) from the C++ Standard Libary (yes, the header spells it like that, I’m not fixing it 😭). The NAME section is literally std::list::empty - std::list::empty β€” recursive icon behavior, we love to see it πŸ’….


✨ Synopsis ✨

Here’s the signature glow-up timeline, no cap:

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

It checks if the container has no elements, i.e. whether begin() == end(). That’s the whole vibe check 🫢.


πŸŽ€ Parameters πŸŽ€

(none) β€” literally zero parameters, not a single one, periodt.


πŸ’– Return value πŸ’–

true if the container is empty, false otherwise. That’s it, that’s the tea πŸ“.


πŸ¦‹ Complexity πŸ¦‹

Constant. Constant, bestie β€” it’s giving stable, predictable, low-drama energy ✨.


🌈 Example 🌈

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

// Run this code

#include <list>
#include <iostream>

int main()
{
    std::list<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)

mwah πŸ’‹ this lil’ page is from http://cppreference.com, version/date 2024.06.10 β€” std::list::empty(3) out πŸ’–βœ¨

πŸ“¦ where this page comes from