allocator::rebind

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

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

Parâmetros

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

Comentários

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

A classe de modelo de membro define o tipo outro.O único propósito é fornecer o nome de tipo allocator<_Outro>, dado o nome de tipo allocator<Tipo>.

Por exemplo, dado um distribuidor o objeto al de 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 ponteiro gravar 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: <memory>

namespace: STD

Consulte também

Referência

allocator Class