# std::forward_list<T,Allocator>::empty

> C++ Atlas: `cppatlas.com/w/cpp/container/forward_list/empty` | Source: https://en.cppreference.com/w/cpp/container/forward_list/empty | Domain: Containers | Standards: C++11

Checks if the container has no elements, i.e. whether begin() == end().

## Official Specification Summary (cppreference)

```cpp
bool empty() const noexcept; // (since C++11)
```

Checks if the container has no elements, i.e. whether `begin() == end()`.

### Parameters

(none)

### Return value

`true` if the container is empty, `false` otherwise.

### Complexity

Constant.

### Example

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

```cpp
#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:

```text
Initially, numbers.empty(): true
After adding elements, numbers.empty(): false
```

### See also

- [`distance`](https://en.cppreference.com/w/cpp/iterator/distance): returns the distance between two iterators (function template)

---
Attribution: content from https://en.cppreference.com/w/cpp/container/forward_list/empty (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.