Compartilhar via


multimap::erase (STL/CLR)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at multimap::erase (STL/CLR).

Removes elements at specified positions.

Syntax

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

Parameters

first
Beginning of range to erase.

key
Key value to erase.

last
End of range to erase.

where
Element to erase.

Remarks

The first member function removes the element of the controlled sequence pointed to by where, and returns an iterator that designates the first element remaining beyond the element removed, or multimap::end (STL/CLR)() if no such element exists. You use it to remove a single element.

The second member function removes the elements of the controlled sequence in the range [``first``, last``), and returns an iterator that designates the first element remaining beyond any elements removed, or end() if no such element exists.. You use it to remove zero or more contiguous elements.

The third member function removes any element of the controlled sequence whose key has equivalent ordering to key, and returns a count of the number of elements removed. You use it to remove and count all elements that match a specified key.

Each element erasure takes time proportional to the logarithm of the number of elements in the controlled sequence.

Example

// cliext_multimap_erase.cpp   
// compile with: /clr   
#include <cliext/map>   
  
typedef cliext::multimap<wchar_t, int> Mymultimap;   
int main()   
    {   
    cliext::multimap<wchar_t, int> c1;   
    c1.insert(cliext::multimap<wchar_t, int>::make_value(L'a', 1));   
    c1.insert(cliext::multimap<wchar_t, int>::make_value(L'b', 2));   
    c1.insert(cliext::multimap<wchar_t, int>::make_value(L'c', 3));   
  
// display contents " [a 1] [b 2] [c 3]"   
    for each (cliext::multimap<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::multimap<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::multimap<wchar_t, int>::make_value(L'd', 4));   
    c1.insert(cliext::multimap<wchar_t, int>::make_value(L'e', 5));   
    for each (cliext::multimap<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);   
    }  
  
 [a 1] [b 2] [c 3]  
erase
(begin()) = [b 2]  
 [b 2] [c 3] [d 4] [e 5]  
erase
(begin(), end
()-1) = [e 5]  
size
() = 1  
erase
(L'x') = 0  
erase
(L'e') = 1  

Requirements

Header: <cliext/map>

Namespace: cliext

See Also

multimap (STL/CLR)
multimap::clear (STL/CLR)