Compartir a través de


allocator::construct

Construye un tipo específico de objeto en una dirección especificada que se inicialice con un valor especificado.

void construct( 
   pointer _Ptr,  
   const Type& _Val 
); 
void construct( 
   pointer _Ptr,  
   Type&& _Val 
); 
template<class _Other> 
    void construct( 
        pointer _Ptr,  
        _Other&&... _Val 
    );

Parámetros

  • _Ptr
    Un puntero a la ubicación donde se construir el objeto.

  • _Val
    El valor con el que el objeto que es construido debe inicializar.

Comentarios

La primera función miembro es equivalente a new ((void *) _Ptr ) Tipo ( _Val ).

Ejemplo

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

using namespace std;

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

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

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

   allocator<int>::pointer v1PtrA;
   int kA = 6, kB = 7;
   v1PtrA = v1Alloc.address( *find( v1.begin( ), v1.end( ), kA ) );
   v1Alloc.destroy ( v1PtrA );
   v1Alloc.construct ( v1PtrA , kB );

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

Requisitos

Encabezado: <memory>

Espacio de nombres: std

Vea también

Referencia

allocator (Clase)

Lvalues y rvalues

Declarador de referencia a un valor L: &

Declarador de referencia a un valor R: &&