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

public member function
template <class InputIterator>
  void assign ( InputIterator first, InputIterator last );
void assign ( size_type n, const T& u );

Assign container content

Assigns new content to the container, dropping all the elements contained in it before the call and replacing them by those specified by the parameters:

In the first version (with iterators), the new contents are a copy of the elements contained in the sequence between first and last (in the range [first,last)).

In the second version, the new content is the repetition n times of copies of element u.

Parameters

first, last
Input iterators to the initial and final positions in a sequence. The range used is [first,last), which includes all the elements between first and last, including the element pointed by first but not the element pointed by last.
The template type can be any type of input iterator.
n
Times that u is repeated to form the new content of the object.
Member type size_type is an unsigned integral type.
u
Value to be repeated n times as the new content of the container.
T is the first class template parameter (the type of the elements stored in the 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
24
25
26
// deque::assign
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
  deque<int> first;
  deque<int> second;
  deque<int> third;
  first.assign (7,100);             // a repetition 7 times of value 100
  deque<int>::iterator it;
  it=first.begin()+1;
  second.assign (it,first.end()-1); // the 5 central values of first
  int myints[] = {1776,7,4};
  third.assign (myints,myints+3);   // assigning from array.
  cout << "Size of first: " << int (first.size()) << endl;
  cout << "Size of second: " << int (second.size()) << endl;
  cout << "Size of third: " << int (third.size()) << endl;
  return 0;
}

Output:
Size of first: 7
Size of second: 5
Size of third: 3

Complexity

Linear on initial and final sizes (destruction, copy construction).

See also