cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : multiset : swap
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
multiset
comparison operators
multiset::multiset
multiset::~multiset
member functions:
· multiset::begin
· multiset::clear
· multiset::count
· multiset::empty
· multiset::end
· multiset::equal_range
· multiset::erase
· multiset::find
· multiset::get_allocator
· multiset::insert
· multiset::key_comp
· multiset::lower_bound
· multiset::max_size
· multiset::operator=
· multiset::rbegin
· multiset::rend
· multiset::size
· multiset::swap
· multiset::upper_bound
· multiset::value_comp

-

multiset::swap public member function
void swap ( multiset<Key,Compare,Allocator>& mst );

Swap content

Exchanges the content of the container with the content of mst, which is another multiset object containing elements of the same type. Sizes may differ.

After the call to this member function, the elements in this container are those which were in mst before the call, and the elements of mst are those which were in this. All iterators, references and pointers remain valid for the swapped objects.

Notice that a global algorithm function exists with this same name, swap, and the same behavior.

Parameters

mst
Another multiset container of the same type as this whose content is swapped with that of this container.

Return value

none

Example

// swap multisets
#include <iostream>
#include <set>
using namespace std;

main ()
{
  int myints[]={19,72,4,36,20,20};
  multiset<int> first (myints,myints+3);     // 4,19,72
  multiset<int> second (myints+3,myints+6);  // 20,20,36
  multiset<int>::iterator it;

  first.swap(second);

  cout << "first contains:";
  for (it=first.begin(); it!=first.end(); it++) cout << " " << *it;

  cout << "\nsecond contains:";
  for (it=second.begin(); it!=second.end(); it++) cout << " " << *it;

  cout << endl;

  return 0;
}

Output:

first contains: 20 20 36
second contains: 4 19 72

Complexity

Constant.

See also

swap

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us