다음을 통해 공유


unordered_map::operator=

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

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

매개 변수

Parameter

설명

_Right

The unordered_map that the operator function assigns content from.

설명

The first version copies all of the elements from _Right to this unordered_map.

The second version moves all of the elements from _Right to this unordered_map.

Any elements that are in this unordered_map before operator= executes are discarded.

예제

// unordered_map_operator_as.cpp
// compile with: /EHsc
#include <unordered_map>
#include <iostream>

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

   v1.insert(pair<int, int>(1, 10));

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

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

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

Output

v1 = 10 
v2 = 10 
v2 = 10 

요구 사항

헤더:<unordered_map>

네임스페이스: std

참고 항목

참조

<unordered_map>

unordered_map 클래스

기타 리소스

<unordered_map> 멤버