다음을 통해 공유


swap 함수(unordered_set)

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

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

매개 변수

  • Key
    키 형식입니다.

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

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

  • Alloc
    The allocator class.

  • left
    The first container to swap.

  • right
    The second container to swap.

설명

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

예제

 

// std_tr1__unordered_set__u_s_swap.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream> 
 
typedef std::unordered_set<char> Myset; 
int main() 
    { 
    Myset c1; 
 
    c1.insert('a'); 
    c1.insert('b'); 
    c1.insert('c'); 
 
// display contents " [c] [b] [a]" 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
    Myset c2; 
 
    c2.insert('d'); 
    c2.insert('e'); 
    c2.insert('f'); 
 
    c1.swap(c2); 
 
// display contents " [f] [e] [d]" 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
    swap(c1, c2); 
 
// display contents " [c] [b] [a]" 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
    return (0); 
    } 
 
  

요구 사항

헤더: <unordered_set>

네임스페이스: std

참고 항목

참조

<unordered_set>

unordered_set::swap

기타 리소스

<unordered_set> 멤버