From cppreference.com
voidpop_back();Removes the last element of the container.
If
is true, the behavior is undefined.
(until C++26)If
is true:
If the implementation is
, a
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