Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

deque::operator=

Replaces the elements of this deque using the elements from another deque.

deque& operator=(
   const deque& _Right
);
deque& operator=(
   deque&& _Right
);

Parameter

Description

_Right

The deque that provides the new content.

The first override copies elements to this deque from _Right, the source of the assignment. The second override moves elements to this deque from _Right.

Elements that are contained in this deque before the operator executes are removed.

// deque_operator_as.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>
using namespace std;

typedef deque<int> MyDeque;

template<typename MyDeque> struct S;

template<typename MyDeque> struct S<MyDeque&> {
  static void show( MyDeque& d ) {
    MyDeque::const_iterator iter;
    for (iter = d.cbegin(); iter != d.cend(); iter++)
       cout << *iter << " ";
    cout << endl;
  }
};

template<typename MyDeque> struct S<MyDeque&&> {
  static void show( MyDeque&& d ) {
    MyDeque::const_iterator iter;
    for (iter = d.cbegin(); iter != d.cend(); iter++)
       cout << *iter << " ";
cout << " via unnamed rvalue reference " << endl;
  }
};

int main( )
{
   MyDeque d1, d2;

   d1.push_back(10);
   d1.push_back(20);
   d1.push_back(30);
   d1.push_back(40);
   d1.push_back(50);

   cout << "d1 = " ;
   S<MyDeque&>::show( d1 );

   d2 = d1;
   cout << "d2 = ";
   S<MyDeque&>::show( d2 );

   cout << "     ";
   S<MyDeque&&>::show ( move< MyDeque& > (d1) );
 }

d1 = 10 20 30 40 50 
d2 = 10 20 30 40 50 
     10 20 30 40 50 via unnamed rvalue reference

Header: <deque>

Namespace: std

Community Additions

ADD
Show:
© 2015 Microsoft