hash_multimap::insert (STL/CLR)

將元素加入。

    iterator insert(value_type val);
    iterator insert(iterator where, value_type val);
    template<typename InIter>
        void insert(InIter first, InIter last);
    void insert(System::Collections::Generic::IEnumerable<value_type>^ right);

參數

  • 第一個
    若要插入範圍的開頭。

  • last
    若要插入範圍的結尾。

  • right
    若要插入的列舉型別。

  • val
    若要插入的機碼值。

  • where
    若要插入 (只有提示) 的容器中的位置。

備註

每個成員函式插入剩下的運算元所指定的序列。

第一個成員函式插入具有值的項目val,並傳回 iterator,指派新插入的項目。您可以用它來插入單一項目。

第二個成員函式插入具有值的項目val、 使用where為提示,(以提升效能),並傳回 iterator,指派新插入的項目。您可以用它來插入單一項目可能會與之相鄰的項目,您知道。

第三個成員函式插入序列[first, last)。您可以用它來插入複製另一個序列中的零或多個項目。

第四個成員函式插入所指定的順序right。您可以用它來插入所描述的列舉值的序列。

每個項目插入要花在受控制序列中項目的數字的對數成比例的時間。插入可出現在 amortized 固定的時間,不過,提供一個提示,將指定的插入點到相鄰的項目。

範例

// cliext_hash_multimap_insert.cpp 
// compile with: /clr 
#include <cliext/hash_map> 
 
typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap; 
int main() 
    { 
    Myhash_multimap c1; 
    c1.insert(Myhash_multimap::make_value(L'a', 1)); 
    c1.insert(Myhash_multimap::make_value(L'b', 2)); 
    c1.insert(Myhash_multimap::make_value(L'c', 3)); 
 
// display contents " [a 1] [b 2] [c 3]" 
    for each (Myhash_multimap::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// insert a single value, unique and duplicate 
    Myhash_multimap::iterator it = 
        c1.insert(Myhash_multimap::make_value(L'x', 24)); 
    System::Console::WriteLine("insert([L'x' 24]) = [{0} {1}]", 
        it->first, it->second); 
 
    it = c1.insert(Myhash_multimap::make_value(L'b', 2)); 
    System::Console::WriteLine("insert([L'b' 2]) = [{0} {1}]", 
        it->first, it->second); 
 
    for each (Myhash_multimap::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// insert a single value with hint 
    it = c1.insert(c1.begin(), Myhash_multimap::make_value(L'y', 25)); 
    System::Console::WriteLine("insert(begin(), [L'y' 25]) = [{0} {1}]", 
        it->first, it->second); 
    for each (Myhash_multimap::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// insert an iterator range 
    Myhash_multimap c2; 
    it = c1.end(); 
    c2.insert(c1.begin(), --it); 
    for each (Myhash_multimap::value_type elem in c2) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// insert an enumeration 
    Myhash_multimap c3; 
    c3.insert(   // NOTE: cast is not needed 
        (System::Collections::Generic:: 
            IEnumerable<Myhash_multimap::value_type>^)%c1); 
    for each (Myhash_multimap::value_type elem in c3) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
    return (0); 
    } 
 
  

需求

標頭: < cliext/hash_map >

Namespace: cliext

請參閱

參考

hash_multimap (STL/CLR)