Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
deque
comparison operators
deque::deque
deque::~deque
member functions:
deque::assign
deque::at
deque::back
deque::begin
deque::clear
deque::empty
deque::end
deque::erase
deque::front
deque::get_allocator
deque::insert
deque::max_size
deque::operator=
deque::operator[]
deque::pop_back
deque::pop_front
deque::push_back
deque::push_front
deque::rbegin
deque::rend
deque::resize
deque::size
deque::swap


deque::back

public member function
      reference back ( );
const_reference back ( ) const;

Access last element

Returns a reference to the last element in the container.

Unlike member deque::end, which returns an iterator just past this element, this function returns a direct reference.

Parameters

none

Return value

A reference to the last element in the deque container.

Member types reference and const_reference are the reference types to the elements of the container (for the default storage allocation model, allocator, these are T& and const T& respectively).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// deque::back
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
  deque<int> mydeque;
  mydeque.push_back(10);
  while (mydeque.back() != 0)
  {
    mydeque.push_back ( mydeque.back() -1 );
  }
  cout << "mydeque contains:";
  for (unsigned i=0; i<mydeque.size() ; i++)
    cout << " " << mydeque[i];
  cout << endl;
  return 0;
}


Output:
mydeque contains: 10 9 8 7 6 5 4 3 2 1 0

Complexity

Constant.

See also