hash_multiset::erase
[!POZNÁMKA]
Toto rozhraní API je zastaralé.Alternativou je unordered_multiset – třída.
Odebere prvek nebo rozsahu prvků v hash_multiset od zadané pozice nebo odebere prvky, které odpovídají zadaným klíčem.
iterator erase(
iterator _Where
);
iterator erase(
iterator _First,
iterator _Last
);
size_type erase(
const key_type& _Key
);
Parametry
_Where
Umístění prvku se liší od hash_multiset._First
Pozice prvního prvku odebrán hash_multiset._Last
Pozice bezprostředně za poslední prvek je odebrán z hash_multiset._Key
Klíč prvky, které mají být odebrány hash_multiset.
Vrácená hodnota
Pro první dvě členské funkce obousměrný iterátor, označí první prvek zbývající za všechny prvky odstraněny nebo ukazatel na konec hash_multiset, pokud neexistuje žádný takový prvek.Třetí členské funkce, počet prvků, které byly odebrány z hash_multiset.
Poznámky
Členské funkce nikdy nevyvolá výjimku.
V aplikaci Visual C++ .NET 2003, členové hlavičkových souborů tříd <hash_map> a <hash_set> již nejsou v oboru názvů std, ale byly přesunuty do oboru názvů stdext.Další informace naleznete v tématu Obor názvů stdext.
Příklad
Při kompilaci v tomto příkladu se /Wp64 příznak, nebo na 64bitovou platformu se vygeneruje kompilátor upozornění C4267.Další informace o upozornění naleznete v tématu Upozornění kompilátoru (úroveň 3) C4267.
// hash_multiset_erase.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>
int main()
{
using namespace std;
using namespace stdext;
hash_multiset<int> hms1, hms2, hms3;
hash_multiset<int> :: iterator pIter, Iter1, Iter2;
int i;
hash_multiset<int>::size_type n;
for (i = 1; i < 5; i++)
{
hms1.insert(i);
hms2.insert(i * i);
hms3.insert(i - 1);
}
// The 1st member function removes an element at a given position
Iter1 = ++hms1.begin();
hms1.erase(Iter1);
cout << "After the 2nd element is deleted,\n "
<< "the hash_multiset hms1 is:" ;
for (pIter = hms1.begin(); pIter != hms1.end(); pIter++)
cout << " " << *pIter;
cout << "." << endl;
// The 2nd member function removes elements
// in the range [_First, _Last)
Iter1 = ++hms2.begin();
Iter2 = --hms2.end();
hms2.erase(Iter1, Iter2);
cout << "After the middle two elements are deleted,\n "
<< "the hash_multiset hms2 is:" ;
for (pIter = hms2.begin(); pIter != hms2.end(); pIter++)
cout << " " << *pIter;
cout << "." << endl;
// The 3rd member function removes elements with a given _Key
n = hms3.erase(2);
cout << "After the element with a key of 2 is deleted,\n "
<< "the hash_multiset hms3 is:" ;
for (pIter = hms3.begin(); pIter != hms3.end(); pIter++)
cout << " " << *pIter;
cout << "." << endl;
// The 3rd member function returns the number of elements removed
cout << "The number of elements removed from hms3 is: "
<< n << "." << endl;
// The dereferenced iterator can also be used to specify a key
Iter1 = ++hms3.begin();
hms3.erase(Iter1);
cout << "After another element with a key "
<< "equal to that of the 2nd element\n is deleted, "
<< "the hash_multiset hms3 is:" ;
for (pIter = hms3.begin(); pIter != hms3.end(); pIter++)
cout << " " << *pIter;
cout << "." << endl;
}
Požadavky
Záhlaví:<hash_set>
Obor názvů: stdext