std::list<T,Allocator>::pop_back - cppreference.com

From cppreference.com

voidpop_back();Removes the last element of the container.

If

empty()

is true, the behavior is undefined.

(until C++26)If

empty()

is true:

If the implementation is

hardened

, a

contract violation

occurs.

If the implementation is not hardened, the behavior is undefined.

(since C++26)References and iterators to the erased element are invalidated.

Complexity

Constant.

Example

Run this code

#include<list>#include<print>intmain(){std::list<int>numbers{1,2,3};for(;notnumbers.empty();numbers.pop_back())std::println("{}",numbers);}Output:

[1, 2, 3] [1, 2] [1] See also