cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : deque : operator=
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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::operator= public member function
deque<T,Allocator>& operator= ( const deque<T,Allocator>& x );

Copy container content

Assigns as the new content for the container a copy of the elements in x.

The elements contained in the object before the call are dropped, and replaced by copies of those in deque x, if any.

After a call to this member function, both the deque and x will have the same size and compare equal to each other.

Parameters

x
A deque object containing elements of the same type.

Return value

*this

Example

// assignment operator with deques
#include <iostream>
#include <deque>
using namespace std;

int main ()
{
  deque<int> first (3);      // deque with 3 zero-initialized ints
  deque<int> second (5);     // deque with 5 zero-initialized ints

  second=first;
  first=deque<int>();

  cout << "Size of first: " << int (first.size()) << endl;
  cout << "Size of second: " << int (second.size()) << endl;
  return 0;
}
Both deque containers of int elements are initialized to sequences with different sizes. Then, second is assigned to first, so both are now equal and with a size of 3. And then, first is assigned to a newly constructed empty container object, so its size is finally 0. Output:
Size of first: 0
Size of second: 3

Complexity

Linear on sizes (destruction, copy construction).

See also

deque::assign Assign container content (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us