hash_set::insert

注意事項注意事項

這個 API 已經過時。這個選項是 unordered_set Class

插入項目或某個範圍的 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 成員函式傳回 bool 元件傳回 true 的配對,如果插入是建立和 false ,如果 hash_set 已經包含索引鍵具有等值的順序,因此, Iterator 元件傳回位址或插入新項目的項目已經放置項目。

若要存取一組 pr 的 Iterator 元件 (此成員函式,請使用 pr.first傳回和解除參考它,請使用 *(pr.first)。若要存取一組 pr 的 bool 元件 (此成員函式,請使用 pr.second傳回和解除參考它,請使用 *(pr.second)。

指向新位置的項目插入 hash_set的第二 insert 成員函式傳回 Iterator。

備註

第三 + 成成員函式插入項目值序列 hash_set 與 Iterator 定址每個項目對應到範圍 [_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

標準樣板程式庫