Compartir a través de


hash_map::difference_type

[!NOTA]

Esta API está obsoleta.La alternativa es unordered_map Class.

Un entero con signo escribe que se puede usar para representar el número de elementos de un hash_map en un intervalo entre elementos indicada por los iteradores.

typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::difference_type difference_type;

Nota

difference_type es el tipo devuelto al restar o aumentando con los iteradores del contenedor.difference_type se utiliza normalmente para representar el número de elementos en el intervalo [_First, _Last) entre el _First de iteradores y _Last, incluye el elemento indicada por _First y el intervalo de elementos hasta, pero no como, el elemento indicada por _Last.

Observe que aunque difference_type está disponible para todos los iteradores que satisfacen los requisitos de un iterador de entrada, que incluye la clase de iteradores bidireccionales admitidos por los contenedores reversibles como conjunto, resta entre los iteradores admite únicamente los iteradores de acceso aleatorio proporcionados por un contenedor de acceso aleatorio, como vector.

En Visual C++ .NET 2003, los miembros de los archivos de encabezado <hash_map> y <hash_set> ya no están en el espacio de nombres std, pero se han movido bastante al espacio de nombres stdext.Vea El espacio de nombres stdext para obtener más información.

Ejemplo

// hash_map_diff_type.cpp
// compile with: /EHsc
#include <iostream>
#include <hash_map>
#include <algorithm>

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_map <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 won't insert, because map keys are unique
   hm1.insert ( Int_Pair ( 2, 30 ) );   

   hash_map <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_map 
   hash_map <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_map 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;
}
  
  
  

Requisitos

Encabezado: <hash_map>

Stdext deEspacio de nombres:

Vea también

Referencia

hash_map Class

Biblioteca de plantillas estándar