Condividi tramite


allocator::rebind

Una struttura che consente a un allocatore per gli oggetti di un tipo per allocare la memoria per oggetti di un altro tipo.

template<class _Other>
   struct rebind {
   typedef allocator<_Other> other;
   };

Parametri

  • altre
    Il tipo di memoria dell'elemento per il quale viene allocando.

Note

Questa struttura è utile per allocare memoria per tipo diverso dal tipo di elemento contenitore che viene distribuito.

La classe modello del membro definisce il tipo altro.L'obiettivo singolo è fornire il < _altrodi allocatordel nome del tipo >, in base al nome del tipo allocator<Tipo>.

Ad esempio, dato un allocatore l'oggetto al di tipo A, è possibile allocare un oggetto di tipo _Other con l'espressione:

A::rebind<Other>::other(al).allocate(1, (Other *)0)

In alternativa, è possibile denominare il tipo di puntatore scrivendo il tipo:

A::rebind<Other>::other::pointer

Esempio

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

using namespace std;

typedef vector<int>::allocator_type IntAlloc;
int main( ) 
{
   IntAlloc v1Iter;
   vector<int> v1;

   IntAlloc::rebind<char>::other::pointer pszC =
      IntAlloc::rebind<char>::other(v1.get_allocator()).allocate(1, (void *)0);

   int * pInt = v1Iter.allocate(10);
}

Requisiti

intestazione: <memory>

Spazio dei nomi: deviazione standard

Vedere anche

Riferimenti

allocator Class