Udostępnij za pośrednictwem


swap Function (unordered_set)

Zamienia zawartość dwóch kontenerów.

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);

Parametry

  • Key
    Typ klucza.

  • Hash
    Typ obiektu funkcji mieszania.

  • Pred
    Typ obiektu funkcji porównania równości.

  • Alloc
    Klasa przydzielania.

  • left
    Pierwszy kontenera, można się przełączyć.

  • right
    Drugim pojemniku można się przełączyć.

Uwagi

Wykonuje funkcję szablonu left.unordered_set::swap(right).

Przykład

 

// 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); 
    } 
 
  

Wymagania

Nagłówek: <unordered_set>

Obszar nazw: std

Zobacz też

Informacje

<unordered_set>

unordered_set::swap

Inne zasoby

<unordered_set> Członkowie