multiset::multiset

Constructs a multiset that is empty or that is a copy of all or part of some other multiset.

multiset( );
explicit multiset (
   const Compare& _Comp
);
multiset (
   const Compare& _Comp,
   const Allocator& _Al
);
set(
   const multiset<Key, Compare, Allocator> & _Right
);
template<class InputIterator> 
   multiset (
      InputIterator _First,
      InputIterator _Last
   );
template<class InputIterator> 
   multiset (
      InputIterator _First,
      InputIterator _Last,
      const Compare& _Comp
   );
template<class InputIterator>
   multiset (
      InputIterator _First,
      InputIterator _Last,
      const Compare& _Comp,
      const Allocator& _Al
   );

Parameters

  • _Al
    The storage allocator class to be used for this multiset object, which defaults to Allocator.

  • _Comp
    The comparison function of type constCompare used to order the elements in the multiset, which defaults to Compare.

  • _Right
    The multiset of which the constructed multiset is to be a copy.

  • _First
    The position of the first element in the range of elements to be copied.

  • _Last
    The position of the first element beyond the range of elements to be copied.

Remarks

All constructors store a type of allocator object that manages memory storage for the multiset and that can later be returned by calling get_allocator. The allocator parameter is often omitted in the class declarations and preprocessing macros used to substitute alternative allocators.

All constructors initialize their multiset.

All constructors store a function object of type Compare that is used to establish an order among the keys of the multiset and that can later be returned by calling key_comp.

The first three constructors specify an empty initial multiset, the second specifying the type of comparison function (_Comp) to be used in establishing the order of the elements and the third explicitly specifying the allocator type (_Al) to be used. The keyword explicit suppresses certain kinds of automatic type conversion.

The fourth constructor specifies a copy of the multiset _Right.

The last three constructors copy the range [_First, _Last) of a multiset with increasing explicitness in specifying the type of comparison function and allocator.

Example

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

int main( )
{
   using namespace std;
   multiset <int>::iterator ms1_Iter, ms2_Iter, ms3_Iter;
   multiset <int>::iterator ms4_Iter, ms5_Iter, ms6_Iter;

   // Create an empty multiset ms0 of key type integer
   multiset <int> ms0;

   // Create an empty multiset ms1 with the key comparison
   // function of less than, then insert 4 elements
   multiset <int, less<int> > ms1;
   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 20 );
   ms1.insert( 40 );

   // Create an empty multiset ms2 with the key comparison
   // function of geater than, then insert 2 elements
   multiset <int, greater<int> > ms2;
   ms2.insert( 10 );
   ms2.insert( 20 );

   // Create a multiset ms3 with the 
   // allocator of multiset ms1
   multiset <int>::allocator_type ms1_Alloc;
   ms1_Alloc = ms1.get_allocator( );
   multiset <int> ms3( less<int>( ), ms1_Alloc );
   ms3.insert( 30 );

   // Create a copy, multiset ms4, of multiset ms1
   multiset <int> ms4( ms1 );

   // Create a multiset ms5 by copying the range ms1[_First, _Last)
   multiset <int>::const_iterator ms1_bcIter, ms1_ecIter;
   ms1_bcIter = ms1.begin( );
   ms1_ecIter = ms1.begin( );
   ms1_ecIter++;
   ms1_ecIter++;
   multiset <int> ms5( ms1_bcIter, ms1_ecIter );

   // Create a multiset ms6 by copying the range ms4[_First, _Last)
   // and with the allocator of multiset ms2
   multiset <int>::allocator_type ms2_Alloc;
   ms2_Alloc = ms2.get_allocator( );
   multiset <int> ms6( ms4.begin( ), ++ms4.begin( ), less<int>( ), ms2_Alloc );

   cout << "ms1 =";
   for ( ms1_Iter = ms1.begin( ); ms1_Iter != ms1.end( ); ms1_Iter++ )
      cout << " " << *ms1_Iter;
   cout << endl;
   
   cout << "ms2 = " << *ms2.begin( ) << " " << *++ms2.begin( )
   << endl;

   cout << "ms3 =";
   for ( ms3_Iter = ms3.begin( ); ms3_Iter != ms3.end( ); ms3_Iter++ )
      cout << " " << *ms3_Iter;
   cout << endl;

   cout << "ms4 =";
   for ( ms4_Iter = ms4.begin( ); ms4_Iter != ms4.end( ); ms4_Iter++ )
      cout << " " << *ms4_Iter;
   cout << endl;

   cout << "ms5 =";
   for ( ms5_Iter = ms5.begin( ); ms5_Iter != ms5.end( ); ms5_Iter++ )
      cout << " " << *ms5_Iter;
   cout << endl;

   cout << "ms6 =";
   for ( ms6_Iter = ms6.begin( ); ms6_Iter != ms6.end( ); ms6_Iter++ )
      cout << " " << *ms6_Iter;
   cout << endl;
}

Output

ms1 = 10 20 20 40
ms2 = 20 10
ms3 = 30
ms4 = 10 20 20 40
ms5 = 10 20
ms6 = 10

Requirements

Header: <set>

Namespace: std

See Also

Concepts

multiset Class

multiset Members

Standard Template Library