map::difference_type
Typ Liczba całkowita ze znakiem, używany do reprezentowania liczbę elementów w zakresie między elementami wskazywanej przez Iteratory mapy.
typedef allocator_type::difference_type difference_type;
Uwagi
difference_type Typ zwracany jest 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 elementu wskazywanego 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 wprowadzania, która zawiera klasę Iteratory dwukierunkowy obsługiwane przez odwracalnego pojemniki takie jak zestaw odejmowania między Iteratory jest obsługiwana tylko przez Iteratory dostępie przewidzianym kontenera dostępie, np. wektorową.
Przykład
// map_diff_type.cpp
// compile with: /EHsc
#include <iostream>
#include <map>
#include <algorithm>
int main( )
{
using namespace std;
map <int, int> m1;
typedef pair <int, int> Int_Pair;
m1.insert ( Int_Pair ( 2, 20 ) );
m1.insert ( Int_Pair ( 1, 10 ) );
m1.insert ( Int_Pair ( 3, 20 ) );
m1.insert ( Int_Pair ( 2, 30 ) );
map <int, int>::iterator m1_Iter, m1_bIter, m1_eIter;
m1_bIter = m1.begin( );
m1_eIter = m1.end( );
// Count the number of elements in a map
map <int, int>::difference_type df_count = 1;
m1_Iter = m1.begin( );
while ( m1_Iter != m1_eIter)
{
df_count++;
m1_Iter++;
}
cout << "The number of elements in the map m1 is: "
<< df_count << "." << endl;
}
Wymagania
Nagłówek: <map>
Obszar nazw: std