Skip to main content

std::forward_list pop_front() method

// Non const version only
constexpr void pop_back();

Removes the first element of the container.

Undefined Behavior

Calling pop_front() on an empty container results in undefined behavior

.

Invalidation

Iterators and references to the last element, are invalidated.

Parameters

(none)

Return value

(none)

Complexity

Constant - O(1).

Exceptions

(none)

Example

Main.cpp
#include <forward_list>
#include <iostream>

int main()
{
std::forward_list<char> chars{'A', 'B', 'C', 'D'};

for (; !chars.empty(); chars.pop_front())
{
std::cout << "chars.front(): '" << chars.front() << "'\n";
}
}
Output
chars.front(): 'A'
chars.front(): 'B'
chars.front(): 'C'
chars.front(): 'D'
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.

std::forward_list pop_front() method

// Non const version only
constexpr void pop_back();

Removes the first element of the container.

Undefined Behavior

Calling pop_front() on an empty container results in undefined behavior

.

Invalidation

Iterators and references to the last element, are invalidated.

Parameters

(none)

Return value

(none)

Complexity

Constant - O(1).

Exceptions

(none)

Example

Main.cpp
#include <forward_list>
#include <iostream>

int main()
{
std::forward_list<char> chars{'A', 'B', 'C', 'D'};

for (; !chars.empty(); chars.pop_front())
{
std::cout << "chars.front(): '" << chars.front() << "'\n";
}
}
Output
chars.front(): 'A'
chars.front(): 'B'
chars.front(): 'C'
chars.front(): 'D'
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.