次の方法で共有


hash_multiset::insert

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
   );

Parameters

  • _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 insert member function returns a pair whose bool component returns true if an insertion was make and false if the hash_multiset already contained an element whose key had an equivalent value in the ordering, and whose iterator component returns the address where a new element was inserted or where the element was already located.

To access the iterator component of a pair pr returned by this member function, use pr.first and to dereference it, use *(pr.first). To access the bool component of a pair pr returned by this member function, use pr.second, and to dereference it, use *(pr.second).

The second insert member function returns an iterator that points to the position where the new element was inserted into the hash_multiset.

Remarks

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.

In Visual C++ .NET 2003, members of the <hash_map> and <hash_set> header files are no longer in the std namespace, but rather have been moved into the stdext namespace. See The stdext Namespace for more information.

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;
}

The original hms1 = 40 10 20 30.
After the insertions, hms1 = 40 10 50 20 20 30.
hms2 = 10 50 20 20 100.

Requirements

Header: <hash_set>

Namespace: stdext

See Also

Concepts

hash_multiset Class

hash_multiset Members

Standard Template Library