다음을 통해 공유


set::operator=

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

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

매개 변수

Parameter

설명

_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;
   }

Output

v1 = 10 
v2 = 10 
v2 = 10 

요구 사항

헤더: <설정>

네임스페이스: std

참고 항목

참조

set 클래스

표준 템플릿 라이브러리

Lvalue 및 Rvalue