Partilhar via


allocator::rebind

Uma estrutura que permite que um alocador para objetos de um tipo para atribuir o armazenamento de objetos de outro tipo.

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

Parâmetros

  • outro
    O tipo de elemento para o qual a memória está sendo atribuído.

Comentários

Essa estrutura é útil para alocar memória para o tipo que difere do tipo de elemento do contêiner que está sendo implementado.

A classe do modelo do membro define o tipo outro. Seu único propósito é fornecer o nome de tipo allocator<_Other>, dado o nome de tipo allocator<Type>.

Por exemplo, em um alocador o objeto al do tipo A, você pode atribuir um objeto do tipo _Other com a expressão:

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

Ou, você pode nomear o tipo de ponteiro gravando o tipo:

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

Exemplo

// 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);
}

Requisitos

Cabeçalho: <memória>

Namespace: std

Consulte também

Referência

Classe allocator