hash_multimap::difference_type
[!UWAGA]
Ten interfejs API jest nieaktualny.Alternatywą jest unordered_multimap — Klasa.
Typ Liczba całkowita, który może służyć do reprezentowania liczbę elementów hash_multimap w zakresie między elementami wskazywanego przez Iteratory.
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::difference_type difference_type;
Uwagi
difference_type Typ zwracany jest po odjęcie lub zwiększany poprzez Iteratory kontenera.difference_type Jest zazwyczaj używany do reprezentowania liczbę elementów w zakresie [_First, _Last) między Iteratory _First i _Last, zawiera element wskazywany przez _First i zakres elementów do, z wyjątkiem elementu wskazywanego przez _Last.
Należy zauważyć, że chociaż difference_type jest dostępna dla wszystkich Iteratory, które spełniają wymogi iteratora wejściowy zawiera klasę Iteratory dwukierunkowy obsługiwane przez odwracalne kontenerów, takie jak zestaw, odejmowanie między Iteratory jest obsługiwana tylko przez Iteratory świadczone przez kontener dostępie losowym np. wektorową.
W Visual C++ .NET 2003, elementy członkowskie plików nagłówka <hash_map> i <hash_set> nie są już w przestrzeni nazw std, ale raczej zostały przeniesione do przestrzeni nazw stdext.Zobacz Przestrzeń nazw stdext, aby uzyskać więcej informacji.
Przykład
// hash_multimap_difference_type.cpp
// compile with: /EHsc
#include <iostream>
#include <hash_map>
#include <algorithm>
int main()
{
using namespace std;
using namespace stdext;
hash_multimap<int, int> hm1;
typedef pair<int, int> Int_Pair;
hm1.insert(Int_Pair(2, 20));
hm1.insert(Int_Pair(1, 10));
hm1.insert(Int_Pair(3, 20));
// The following will insert, because map keys
// do not need to be unique
hm1.insert(Int_Pair(2, 30));
hash_multimap<int, int>::iterator hm1_Iter, hm1_bIter, hm1_eIter;
hm1_bIter = hm1.begin();
hm1_eIter = hm1.end();
// Count the number of elements in a hash_multimap
hash_multimap<int, int>::difference_type df_count = 0;
hm1_Iter = hm1.begin();
while (hm1_Iter != hm1_eIter)
{
df_count++;
hm1_Iter++;
}
cout << "The number of elements in the hash_multimap hm1 is: "
<< df_count << "." << endl;
cout << "The keys of the mapped elements are:";
for (hm1_Iter= hm1.begin() ; hm1_Iter!= hm1.end();
hm1_Iter++)
cout << " " << hm1_Iter-> first;
cout << "." << endl;
cout << "The values of the mapped elements are:";
for (hm1_Iter= hm1.begin() ; hm1_Iter!= hm1.end();
hm1_Iter++)
cout << " " << hm1_Iter-> second;
cout << "." << endl;
}
Wymagania
Nagłówek: <hash_map>
Przestrzeń nazw: stdext