次の方法で共有


hash_set::insert

[!メモ]

この API は、互換性のために残されています。代わりに unordered_set クラスです。

hash_setに要素または要素範囲を挿入します。

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

パラメーター

パラメーター

説明

_Val

hash_set が既にその要素をか、キーが同じで並べる要素をよりよくある場合 hash_set に挿入する要素の値。

_Where

挿入の正しいポイントの検索を開始する位置。(挿入に対数の時間ではなく償却定数時間で挿入位置がの _Whereに従うと、生成される場合があります)。

_First

hash_setからコピーする最初の要素の位置。

_Last

hash_setコピー元の最後の要素だけを越える位置。

戻り値

最初の insert のメンバー関数は hash_set が既にキーに対応した順序で、反復子のコンポーネントが要素が既に発生した位置に新しい要素を挿入するか、またはaddressを返す要素が含まれている場合は、挿入します false がある場合は bool のコンポーネントが true を返すペアを返します。

ペア pr の反復子のコンポーネントにアクセスし、を使用 *(pr.first)逆参照するには、このメンバー関数は、を使用 pr.first によって返される。ペア pr の bool のコンポーネントにアクセスし、逆参照するには、このメンバー関数は、pr.second使用して、使用 *(pr.second)返されました。

2番目の insert のメンバー関数は新しい要素が hash_setに挿入位置を指す反復子を返します。

解説

3番目のメンバー関数は、指定 hash_setの範囲[_First、_Last) の反復子によってアドレス各要素に対応する hash_set に要素値のシーケンスを挿入します。

使用例

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

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_set <int>::iterator hs1_pIter, hs2_pIter;

   hash_set <int, hash_compare <int, less<int> > > hs1, hs2;
   hs1.insert( 10 );
   hs1.insert( 20 );
   hs1.insert( 30 );
   hs1.insert( 40 );

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

   pair< hash_set<int>::iterator, bool > pr;
   pr = hs1.insert( 10 );

   if(pr.second == true)
   {
      cout << "The element 10 was inserted in hs1 successfully."
           << endl;
   }
   else
   {
      cout << "The element 10 already exists in hs1 and"
           << " *( pr.first ) = " << *( pr.first ) << "."
           << endl;
   }

   hs1.insert( --hs1.end( ), 50 );

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

   hs2.insert( 100 );
   hs2.insert( ++hs1.begin( ), --hs1.end( ) );

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

必要条件

ヘッダー: <hash_set>

名前空間: のstdext

参照

関連項目

hash_set Class

標準テンプレート ライブラリ