Partager via


hash_multiset::hash_multiset

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

hash_multiset( );
explicit hash_multiset(
   const Traits& _Comp
);
hash_multiset(
   const Traits& _Comp,
   const Allocator& _Al
);
hash_multiset(
   const hash_multiset<Key, Traits, Allocator>& _Right
);
template<class InputIterator>
   hash_multiset(
      InputIterator _First,
      InputIterator _Last
   );
template<class InputIterator>
   hash_multiset(
      InputIterator _First,
      InputIterator _Last,
      const Traits& _Comp
   );
template<class InputIterator>
   hash_multiset(
      InputIterator _First,
      InputIterator _Last,
      const Traits& _Comp,
      const Allocator& _Al
   );
hash_multiset(
   hash_multiset&& _Right
};

Parameters

Parameter

Description

_Al

The storage allocator class to be used for this hash_multiset object, which defaults to Allocator.

_Comp

The comparison function of type const Traits used to order the elements in the hash_multiset, which defaults to hash_compare.

_Right

The hash_multiset of which the constructed hash_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 hash_multiset and that can later be returned by calling hash_multiset::get_allocator. The allocator parameter is often omitted in the class declarations and preprocessing macros used to substitute alternative allocators.

All constructors initialize their hash_multisets.

All constructors store a function object of type Traits that is used to establish an order among the keys of the hash_multiset and that can later be returned by calling hash_multiset::key_comp. For more information on Traits see the hash_multiset Class topic.

The first three constructors specify an empty initial hash_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 hash_multiset _Right.

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

The last constructor moves the hash_multiset _Right.

The actual order of elements in a hashed set container depends on the hash function, the ordering function and the current size of the hash table and cannot, in general, be predicted as it could with the set container, where it was determined by the ordering function alone.

Example

// hash_multiset_hash_multiset.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_multiset <int>::iterator hms1_Iter, hms3_Iter, hms4_Iter,
      hms5_Iter, hms6_Iter, hms7_Iter;
   hash_multiset <int, hash_compare <int, greater<int> > >::iterator
      hms2_Iter;

   // Create an empty hash_multiset hs0 of key type integer
   hash_multiset <int> hs0;

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

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

   // Create a hash_multiset hms3 with the 
   // allocator of hash_multiset hms1
   hash_multiset <int>::allocator_type hms1_Alloc;
   hms1_Alloc = hms1.get_allocator( );
   hash_multiset <int> hms3( hash_compare <int, less<int> >( ),
      hms1_Alloc );
   hms3.insert( 30 );

   // Create a copy, hash_multiset hms4, of hash_multiset hms1
   hash_multiset <int> hms4( hms1 );

   // Create a hash_multiset hms5 by copying the range hms1[_First, _Last)
   hash_multiset <int>::const_iterator hms1_bcIter, hms1_ecIter;
   hms1_bcIter = hms1.begin( );
   hms1_ecIter = hms1.begin( );
   hms1_ecIter++;
   hms1_ecIter++;
   hash_multiset <int> hms5( hms1_bcIter, hms1_ecIter );

   // Create a hash_multiset hms6 by copying the range hms4[_First, _Last)
   // and with the allocator of hash_multiset hms2
   hash_multiset <int>::allocator_type hms2_Alloc;
   hms2_Alloc = hms2.get_allocator( );
   hash_multiset <int> hms6( hms4.begin( ), ++hms4.begin( ), 
      less<int>( ), hms2_Alloc );

   cout << "hms1 = ";
   for ( hms1_Iter = hms1.begin( ); hms1_Iter != hms1.end( );
         hms1_Iter++ )
      cout << *hms1_Iter << " ";
   cout << endl;
   
   cout << "hms2 = " ;
   for ( hms2_Iter = hms2.begin( ); hms2_Iter != hms2.end( );
         hms2_Iter++ )
      cout << *hms2_Iter << " ";
   cout << endl;

   cout << "hms3 = ";
   for ( hms3_Iter = hms3.begin( ); hms3_Iter != hms3.end( );
         hms3_Iter++ )
      cout << *hms3_Iter << " ";
   cout << endl;

   cout << "hms4 = ";
   for ( hms4_Iter = hms4.begin( ); hms4_Iter != hms4.end( );
         hms4_Iter++ )
      cout << *hms4_Iter << " ";
   cout << endl;

   cout << "hms5 = ";
   for ( hms5_Iter = hms5.begin( ); hms5_Iter != hms5.end( );
         hms5_Iter++ )
      cout << *hms5_Iter << " ";
   cout << endl;

   cout << "hms6 = ";
   for ( hms6_Iter = hms6.begin( ); hms6_Iter != hms6.end( );
         hms6_Iter++ )
      cout << *hms6_Iter << " ";
   cout << endl;

    // Create a copy, hash_multiset hms7, of hash_multiset hms1 by moving
    hash_multiset <int, hash_compare <int, less<int> > >
        hms7(move(hms1);
    cout << "hms7 =";
    for (hms7_Iter = hms7.begin(); hms7_Iter != hms7.end(); hms7_Iter++)
        cout << " " << hms7_Iter -> second;
    cout << endl;
}

Output

hms1 = 40 10 20 30 
hms2 = 10 20 
hms3 = 30 
hms4 = 40 10 20 30 
hms5 = 40 10 
hms6 = 40 
hms7 = 40 10 20 30 

Requirements

Header: <hash_set>

Namespace: stdext

See Also

Reference

hash_multiset Class

Standard Template Library

Other Resources

hash_multiset Members