hash_multimap::difference_type
참고
이 API는 사용되지 않습니다.unordered_multimap 클래스를 대신 사용하는 것이 좋습니다.
A signed integer type that can be used to represent the number of elements of a hash_multimap in a range between elements pointed to by iterators.
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::difference_type difference_type;
설명
The difference_type is the type returned when subtracting or incrementing through iterators of the container. The difference_type is typically used to represent the number of elements in the range [_First, _Last) between the iterators _First and _Last, includes the element pointed to by _First and the range of elements up to, but not including, the element pointed to by _Last.
Note that although difference_type is available for all iterators that satisfy the requirements of an input iterator, which includes the class of bidirectional iterators supported by reversible containers such as set, subtraction between iterators is only supported by random-access iterators provided by a random-access container such as vector.
Visual C++.NET 2003에서, <hash_map> 및 <hash_set> 헤더 파일의 멤버는 더 이상 std 네임스페이스에 존재하지 않습니다. 대신 stdext 네임스페이스로 이동되었습니다. 자세한 내용은 stdext 네임스페이스를 참조하십시오.
예제
// 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;
}
요구 사항
헤더: <hash_map>
네임스페이스: stdext