Compartilhar via


set::swap

Troca os elementos de dois conjuntos.

void swap(
   set<Key, Traits, Allocator>& _Right
);

Parâmetros

  • _Right
    O conjunto de argumento que fornece os elementos a ser alternado com o conjunto de destino.

Comentários

A função de membro não invalida referência, nenhum ponteiro, ou iterador que os elementos designados nos dois conjuntos cujos elementos estão sendo trocados.

Exemplo

// set_swap.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   set <int>::iterator s1_Iter;

   s1.insert( 10 );
   s1.insert( 20 );
   s1.insert( 30 );
   s2.insert( 100 );
   s2.insert( 200 );
   s3.insert( 300 );

   cout << "The original set s1 is:";
   for ( s1_Iter = s1.begin( ); s1_Iter != s1.end( ); s1_Iter++ )
      cout << " " << *s1_Iter;
   cout   << "." << endl;

   // This is the member function version of swap
   s1.swap( s2 );

   cout << "After swapping with s2, list s1 is:";
   for ( s1_Iter = s1.begin( ); s1_Iter != s1.end( ); s1_Iter++ )
      cout << " " << *s1_Iter;
   cout  << "." << endl;

   // This is the specialized template version of swap
   swap( s1, s3 );

   cout << "After swapping with s3, list s1 is:";
   for ( s1_Iter = s1.begin( ); s1_Iter != s1.end( ); s1_Iter++ )
      cout << " " << *s1_Iter;
   cout   << "." << endl;
}
  

Requisitos

defineCabeçalho: <>

Namespace: std

Consulte também

Referência

Classe set

set::swap, set::begin e set::end

Biblioteca de Modelos Padrão