hash_map::erase (STL/CLR)

移除指定位置的項目。

    iterator erase(iterator where);
    iterator erase(iterator first, iterator last);
    bool erase(key_type key)

參數

  • 第一個
    要清除範圍的開頭。

  • Key - 索引鍵
    若要清除的機碼值。

  • last
    要清除範圍的結尾。

  • where
    若要清除的項目。

備註

第一個成員函式會移除所指的受控制序列的項目where,並傳回 iterator,指派第一個以外的項目移除,剩餘的項目或hash_map::end (STL/CLR)()如果沒有這類項目。您可以用它來移除單一項目。

第二個成員函式會受控制序列的元素範圍中加以移除[first, last),並傳回 iterator,指派第一個以外的任何項目移除,剩餘的項目或end()如果沒有這類項目。.您可以用它來移除零或多個連續的項目。

第三個成員函式會移除任何其索引鍵有對等排序受控制序列的項目至key,並傳回已移動元素的數目。您可以用它來移除,並計算所有符合指定的索引鍵的項目。

每個項目清除時要花在受控制序列中項目的數字的對數成比例的時間。

範例

// cliext_hash_map_erase.cpp 
// compile with: /clr 
#include <cliext/hash_map> 
 
typedef cliext::hash_map<wchar_t, int> Myhash_map; 
int main() 
    { 
    cliext::hash_map<wchar_t, int> c1; 
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'a', 1)); 
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'b', 2)); 
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'c', 3)); 
 
// display contents " [a 1] [b 2] [c 3]" 
    for each (cliext::hash_map<wchar_t, int>::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// erase an element and reinspect 
    cliext::hash_map<wchar_t, int>::iterator it = 
        c1.erase(c1.begin()); 
    System::Console::WriteLine("erase(begin()) = [{0} {1}]", 
        it->first, it->second); 
 
// add elements and display " b c d e" 
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'd', 4)); 
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'e', 5)); 
    for each (cliext::hash_map<wchar_t, int>::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// erase all but end 
    it = c1.end(); 
    it = c1.erase(c1.begin(), --it); 
    System::Console::WriteLine("erase(begin(), end()-1) = [{0} {1}]", 
        it->first, it->second); 
    System::Console::WriteLine("size() = {0}", c1.size()); 
 
// erase end 
    System::Console::WriteLine("erase(L'x') = {0}", c1.erase(L'x')); 
    System::Console::WriteLine("erase(L'e') = {0}", c1.erase(L'e')); 
    return (0); 
    } 
 
  

需求

標頭: < cliext/hash_map >

Namespace: cliext

請參閱

參考

hash_map (STL/CLR)

hash_map::clear (STL/CLR)