allocator::difference_type

Podpisana rodzaju integralną może stanowić różnicę między wartościami wskaźniki do typu obiektu, zarządzane przez program przydzielania.

typedef ptrdiff_t difference_type;

Uwagi

Typ Liczba całkowita opisuje obiekt, który może stanowić różnicę między adresami wszelkie dwa elementy w sekwencji, który obiekt programu przydzielania szablonu klasy można przydzielić.

Przykład

// allocator_diff_type.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <vector>

using namespace std;

int main( ) 
{
   vector <int> v1;
   vector <int>::iterator v1Iter;
   vector <int>:: allocator_type v1Alloc;

   int i;
   for ( i = 0 ; i <= 7 ; i++ )
   {
      v1.push_back( i * 2 );
   }

   cout << "The original vector v1 is:\n ( " ;
   for ( v1Iter = v1.begin( ) ; v1Iter != v1.end( ) ; v1Iter++ )
      cout << *v1Iter << " ";
   cout << ")." << endl;

   allocator<int>::const_pointer v1PtrA, v1PtrB;
   const int kA = 4, kB =12;
   v1PtrA = v1Alloc.address( kA );
   v1PtrB = v1Alloc.address( kB );
   allocator<int>::difference_type v1diff = *v1PtrB - *v1PtrA;

   cout << "Pointer v1PtrA addresses " << *v1PtrA << "." << endl;
   cout << "Pointer v1PtrB addresses " << *v1PtrB <<  "." << endl;
   cout << "The difference between the integer's addresses is: "
        << v1diff << "." << endl;
}
  

Wymagania

Nagłówek: <pamięć>

Przestrzeń nazw: std

Zobacz też

Informacje

allocator — Klasa