public member function
<deque>

std::deque::pop_back

void pop_back();
Delete last element
Removes the last element in the deque container, effectively reducing the container size by one.

This destroys the removed element.

Parameters

none

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// deque::pop_back
#include <iostream>
#include <deque>

int main ()
{
  std::deque<int> mydeque;
  int sum (0);
  mydeque.push_back (10);
  mydeque.push_back (20);
  mydeque.push_back (30);

  while (!mydeque.empty())
  {
    sum+=mydeque.back();
    mydeque.pop_back();
  }

  std::cout << "The elements of mydeque add up to " << sum << '\n';

  return 0;
}


In this example, the elements are popped out from the end of the deque after they are added up in the sum. Output:
The elements of mydeque add up to 60

Complexity

Constant.

Iterator validity

The end iterator and any iterator, pointer and reference referring to the removed element are invalidated.
Iterators, pointers and references referring to other elements that have not been removed are guaranteed to keep referring to the same elements they were referring to before the call.

Data races

The container is modified.
The last element is modified. Concurrently accessing or modifying other elements is safe (although see iterator validity above).

Exception safety

If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, the behavior is undefined.

See also