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.