std::flat_set::empty(3)

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

std::flat_set::empty β€” C++ Standard Libary manual, section 3 πŸ¦‹

okay bestie, welcome to the C++ Standard Libary manual, section 3 β€” this page is std::flat_set::empty, and it's lowkey adorable. πŸ’–

NAME πŸ’…

std::flat_set::empty - std::flat_set::empty β€” yes bestie, the name is the name. Self-referential icon behavior.

Synopsis ✨

Here's the signature, fresh since C++23:

[[nodiscard]] bool empty() const noexcept;  (since C++23)

Checks if the underlying container has no elements. Equivalent to return begin() == end();.

Parameters πŸŽ€

(none) β€” literally zero parameters. Not a single one, bestie.

Return value πŸ’–

true if the underlying container is empty, false otherwise. Simple. Clean. Slay.

Complexity 🌈

Constant. Periodt.

Example πŸ“

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

// Run this code

#include <iostream>
#include <flat_set>

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

    numbers.insert(42);
    numbers.insert(19937);
    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)

source/version: http://cppreference.com, date: 2024.06.10 β€” okay bye bestie, go check if your container is empty, ily πŸ’œ

πŸ“¦ where this page comes from