This documentation is archived and is not being maintained.

set::operator=

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

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

Parameter

Description

_Right

The set providing new elements to be assigned to this set.

The first version of operator= uses an lvalue reference for _Right, to copy elements from _Right to this set.

The second version uses an rvalue reference for _Right. It moves elements from _Right to this set.

Any elements in this set before the operator function executes are discarded.

// set_operator_as.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
   {
   using namespace std;
   set<int> v1, v2, v3;
   set<int>::iterator iter;

   v1.insert(10);

   cout << "v1 = " ;
   for (iter = v1.begin(); iter != v1.end(); iter++)
      cout << *iter << " ";
   cout << endl;

   v2 = v1;
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << *iter << " ";
   cout << endl;

// move v1 into v2
   v2.clear();
   v2 = move(v1);
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << *iter << " ";
   cout << endl;
   }

v1 = 10 
v2 = 10 
v2 = 10 

Header: <set>

Namespace: std

Show: