public member function
<forward_list>

std::forward_list::empty

bool empty() const noexcept;
Test whether array is empty
Returns a bool value indicating whether the forward_list container is empty, i.e. whether its size is 0.

This function does not modify the content of the container in any way. To clear the content of an array object, see forward_list::clear.

Parameters

none

Return Value

true if the container size is 0, false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// forward_list::empty
#include <iostream>
#include <forward_list>

int main ()
{
  std::forward_list<int> first;
  std::forward_list<int> second = {20, 40, 80};
  std::cout << "first " << (first.empty() ? "is empty" : "is not empty" ) << std::endl;
  std::cout << "second " << (second.empty() ? "is empty" : "is not empty" ) << std::endl;
  return 0;
}

Output:
first is empty
second is not empty


Complexity

Constant.

Iterator validity

No changes.

Data races

The container is accessed.
No contained elements are accessed: concurrently accessing or modifying them is safe.

Exception safety

No-throw guarantee: this member function never throws exceptions.

See also