Partager via


allocator::rebind

Une structure qui permet à un allocateur d'objets de type pour allouer le stockage des objets d'un autre type.

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

Paramètres

  • autres
    Le type d'élément pour lequel la mémoire allouée.

Notes

Cette structure est utile pour allouer de la mémoire pour le type qui est différent du type du conteneur est implémenté.

La classe de modèle membre définit le type autre. Son seul objectif est de fournir _Autre>de<allocatorde type, d'après le nom allocator<Type>de type.

Par exemple, considérons un objet d'allocation al de type A, vous pouvez allouer un objet de type _Other avec l'expression suivante :

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

Ou, vous pouvez attribuer le type de pointeur en entrant le type :

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

Exemple

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

Configuration requise

En-tête: <mémoire>

Espace de noms : std

Voir aussi

Référence

allocator, classe