Namespaces
Variants

std::list<T,Allocator>::pop_back

From cppreference.com
 
 
 
 
void pop_back();

Removes the last element of the container.

If empty() is true, the behavior is undefined.

(until C++26)

If empty() is true:

(since C++26)

References and iterators to the erased element are invalidated.

Complexity

Constant.

Example

#include <list>
#include <print>

int main()
{
    std::list<int> numbers{1, 2, 3};
    for (; not numbers.empty(); numbers.pop_back())
        std::println("{}", numbers);
}

Output:

[1, 2, 3]
[1, 2]
[1]

See also

removes the first element
(public member function) [edit]
adds an element to the end
(public member function) [edit]