다음을 통해 공유


swap 함수(unordered_multimap)

두 컨테이너의 내용을 바꿉니다.

template<class Key, class Ty, class Hash, class Pred, class Alloc>
    void swap(
        unordered_multimap <Key, Ty, Hash, Pred, Alloc>& left,
        unordered_multimap <Key, Ty, Hash, Pred, Alloc>& right);

매개 변수

  • Key
    키 형식입니다.

  • Ty
    매핑된 형식입니다.

  • Hash
    해시 함수 개체 형식입니다.

  • Pred
    같음 비교 함수 개체 형식.

  • Alloc
    The allocator class.

  • left
    The first container to swap.

  • right
    The second container to swap.

설명

The template function executes left.unordered_multimap::swap(right).

예제

 

// std_tr1__unordered_map__u_mm_swap.cpp 
// compile with: /EHsc 
#include <unordered_map> 
#include <iostream> 
 
typedef std::unordered_multimap<char, int> Mymap; 
int main() 
    { 
    Mymap c1; 
 
    c1.insert(Mymap::value_type('a', 1)); 
    c1.insert(Mymap::value_type('b', 2)); 
    c1.insert(Mymap::value_type('c', 3)); 
 
// display contents " [c 3] [b 2] [a 1]" 
    for (Mymap::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << it->first << ", " << it->second << "]"; 
    std::cout << std::endl; 
 
    Mymap c2; 
 
    c2.insert(Mymap::value_type('d', 4)); 
    c2.insert(Mymap::value_type('e', 5)); 
    c2.insert(Mymap::value_type('f', 6)); 
 
    c1.swap(c2); 
 
// display contents " [f 6] [e 5] [d 4]" 
    for (Mymap::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << it->first << ", " << it->second << "]"; 
    std::cout << std::endl; 
 
    swap(c1, c2); 
 
// display contents " [c 3] [b 2] [a 1]" 
    for (Mymap::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << it->first << ", " << it->second << "]"; 
    std::cout << std::endl; 
 
    return (0); 
    } 
 
  

요구 사항

헤더:<unordered_map>

네임스페이스: std

참고 항목

참조

<unordered_map>

unordered_multimap::swap

기타 리소스

<unordered_map> 멤버