std::forward_list::empty(3)
π std::forward_list::empty(3) π
okay so welcome to std::forward_list::empty(3) from the C++ Standard Libary β yes bestie, thatβs the manual name and weβre rolling with it. This is literally the vibe check for your std::forward_list: is it empty or not? Main character energy for a tiny function, honestly. π
π NAME π
std::forward_list::empty β std::forward_list::empty
yes, the name is the name and we love a self-referential icon. no notes. π
πΈ Synopsis πΈ
bool empty() const noexcept; (since C++11)
(until C++20)
[[nodiscard]] bool empty() const noexcept; (since C++20)
She checks if the container has no elements, i.e. whether begin() == end(). Thatβs the whole assignment. π«Ά
π Parameters π
(none)
literally zero parameters. not a single one. she takes no arguments and still serves. β¨
π Return value π
true if the container is empty, false otherwise.
thatβs it. thatβs the answer. cute, concise, correct. π
π₯ Complexity π₯
Constant.
no dramatic runtime arc, no surprise side quest. constant energy. π
π¦ Example π¦
The following code uses empty to check if a std::forward_list<int> contains any elements:
// Run this code
#include <forward_list>
#include <iostream>
int main()
{
std::forward_list<int> numbers;
std::cout << std::boolalpha;
std::cout << "Initially, numbers.empty(): " << numbers.empty() <<
'\n';
numbers.push_front(42);
numbers.push_front(13317);
std::cout << "After adding elements, numbers.empty(): " <<
numbers.empty() << '\n';
}
β¨ Output β¨
Initially, numbers.empty(): true
After adding elements, numbers.empty(): false
look at her go. empty at first, then not empty after push_front(42) and push_front(13317). iconic behavior. π
π See also π
distanceβ returns the distance between two iterators (function template)
catch you later, bestie β this page came from http://cppreference.com, dated 2024.06.10, and itβs signing off with maximum sparkle. mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms