Share via


hash_multiset::insert

Note

This API is obsolete. The alternative is unordered_multiset Class.

Inserts an element or a range of elements into a hash_multiset.

iterator insert(
   const value_type& _Val
);
iterator insert(
   iterator _Where,
   const value_type& _Val
);
template<class InputIterator>
   void insert(
      InputIterator _First,
      InputIterator _Last
   );
template<class ValTy>
    iterator insert(
        ValTy&& _Val
);
template<class ValTy>
    iterator insert(
        const_iterator _Where,
        ValTy&& _Val
);

Parameters

Parameter

Description

_Val

The value of an element to be inserted into the hash_multiset unless the hash_multiset already contains that element or, more generally, an element whose key is equivalently ordered.

_Where

The place to start searching for the correct point of insertion. (Insertion can occur in amortized constant time, instead of logarithmic time, if the insertion point immediately follows _Where.)

_First

The position of the first element to be copied from a hash_multiset.

_Last

The position just beyond the last element to be copied from a hash_multiset.

Return Value

The first two insert member functions return an iterator that points to the position where the new element was inserted.

The last two insert member functions behave the same as the first two, except that they move construct the inserted value.

Remarks

Insertion can occur in amortized constant time for the hint version of insert, instead of logarithmic time, if the insertion point immediately follows _Where.

The third member function inserts the sequence of element values into a hash_multiset corresponding to each element addressed by an iterator of in the range [_First, _Last) of a specified hash_multiset.

Example

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

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_multiset <int>::iterator hms1_pIter, hms2_pIter;

   hash_multiset <int, hash_compare <int, less<int> > > hms1, hms2;
   hms1.insert( 10 );
   hms1.insert( 20 );
   hms1.insert( 30 );
   hms1.insert( 40 );

   cout << "The original hms1 =";
   for ( hms1_pIter = hms1.begin( ); hms1_pIter != hms1.end( );
         hms1_pIter++ )
      cout << " " << *hms1_pIter;
   cout << "." << endl;


   hms1.insert( 20 );
   hms1.insert( --hms1.end( ), 50 );

   cout << "After the insertions, hms1 =";
   for ( hms1_pIter = hms1.begin( ); hms1_pIter != hms1.end( );
         hms1_pIter++ )
      cout << " " << *hms1_pIter;
   cout << "." << endl;

   hms2.insert( 100 );
   hms2.insert( ++hms1.begin( ), --hms1.end( ) );

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

   // move construct an element
   hash_multiset<string> hms3, hms4;
   string str1("a"), str2("b");

   hms3.insert(move(str1));
   cout << "After the move insertion, hms3 contains "
      << *hms3.begin() << "." << endl;

   hms4.insert(hms4.begin(), move(str1));
   cout << "After the move insertion, hms4 contains "
      << *hms4.begin() << "." << endl;
}
The original hms1 = 40 10 20 30.
After the insertions, hms1 = 40 10 50 20 20 30.
hms2 = 10 50 20 20 100. 
After the move insertion, hms3 contains a.
After the move insertion, hms4 contains b.

Requirements

Header: <hash_set>

Namespace: stdext

See Also

Reference

hash_multiset Class

Standard Template Library