Condividi tramite


deque::swap

Exchanges the elements of two deques.

void swap(
   deque<Type, Allocator>& _Right
);
friend void swap(
   deque<Type, Allocator>& _Left,
   deque<Type, Allocator>& _Right
)
template<class Type, class Allocator>
void swap(
   deque< Type, Allocator>& _Left, 
   deque< Type, Allocator>& _Right
);

Parameters

  • _Right
    The deque providing the elements to be swapped, or the deque whose elements are to be exchanged with those of the deque _Left.

  • _Left
    A deque whose elements are to be exchanged with those of the deque _Right.

Example

// deque_swap.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>

int main( ) 
{
   using namespace std;
   deque <int> c1, c2, c3;
   deque <int>::iterator c1_Iter;

   c1.push_back( 1 );
   c1.push_back( 2 );
   c1.push_back( 3 );
   c2.push_back( 10 );
   c2.push_back( 20 );
   c3.push_back( 100 );

   cout << "The original deque c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   c1.swap( c2 );

   cout << "After swapping with c2, deque c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   swap( c1,c3 );

   cout << "After swapping with c3, deque c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   swap<>(c1, c2);
   cout << "After swapping with c2, deque c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;
}
The original deque c1 is: 1 2 3
After swapping with c2, deque c1 is: 10 20
After swapping with c3, deque c1 is: 100
After swapping with c2, deque c1 is: 1 2 3

Requirements

Header: <deque>

Namespace: std

See Also

Reference

deque Class

deque::assign and deque::swap

Standard Template Library

Other Resources

deque Class Members