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::swap

public member function
void swap ( deque<T,Allocator>& dqe );

Swap content

Exchanges the content of the vector by the content of dqe, which is another deque object containing elements of the same type. Sizes may differ.

After the call to this member function, the elements in this container are those which were in dqe before the call, and the elements of dqe are those which were in this. All iterators, references and pointers remain valid for the swapped objects.

Notice that a global algorithm function exists with this same name, swap, and the same behavior.

Parameters

dqe
Another deque container of the same type as this whose content is swapped with that of this container.

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
23
// swap deques
#include <iostream>
#include <deque>
using namespace std;
main ()
{
  unsigned int i;
  deque<int> first (3,100);   // three ints with a value of 100
  deque<int> second (5,200);  // five ints with a value of 200
  first.swap(second);
  cout << "first contains:";
  for (i=0; i<first.size(); i++) cout << " " << first[i];
  cout << "\nsecond contains:";
  for (i=0; i<second.size(); i++) cout << " " << second[i];
  cout << endl;
  return 0;
}


Output:
first contains: 200 200 200 200 200 
second contains: 100 100 100 

Complexity

Constant.

See also