cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : multiset : operator=
- -
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::operator= public member function
multiset<Key,Compare,Allocator>&
  operator= ( const multiset<Key,Compare,Allocator>& x );

Copy container content

Assigns a copy of the elements in x as the new content for the container.

The elements contained in the object before the call are dropped, and replaced by copies of those in multiset x, if any.

After a call to this member function, both the multiset object and x will have the same size and compare equal to each other.

Parameters

x
A multiset object with the same class template parameters (Key, Compare and Allocator).

Return value

*this

Example

// assignment operator with multisets
#include <iostream>
#include <set>
using namespace std;

int main ()
{
  int myints[]={ 19,81,36,36,19 };
  multiset<int> first (myints,myints+5);   // multiset with 5 ints
  multiset<int> second;                    // empty multiset

  second=first;                            // now second contains the 5 ints
  first=multiset<int>();                   // and first is empty

  cout << "Size of first: " << int (first.size()) << endl;
  cout << "Size of second: " << int (second.size()) << endl;
  return 0;
}
Output:
Size of first: 0
Size of second: 5

Complexity

Linear on sizes (destruction, copy construction).

See also

multiset::insert Insert element (public member function)
multiset::multiset Construct multiset (public member function)

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