다음을 통해 공유


uninitialized_fill

지정된 값의 개체를 초기화되지 않은 대상 범위로 복사합니다.

template<class ForwardIterator, class Type> 
   void uninitialized_fill( 
      ForwardIterator _First,  
      ForwardIterator _Last, 
      const Type& _Val 
   );

매개 변수

  • _First
    A forward iterator addressing the first element in the destination range that is to be initiated.

  • _Last
    A forward iterator addressing the last element in the destination range that is to be initiated.

  • _Val
    The value to be used to initialize the destination range.

설명

This algorithm allows the decoupling of memory allocation from object construction.

The template function effectively executes:

while ( _First!= _Last )
   new ( (void *)&*_First ++)
      iterator_traits<ForwardIterator>::value_type ( _Val );

unless the code throws an exception. In that case, all constructed objects are destroyed and the exception is rethrown.

예제

// memory_uninit_fill.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>

using namespace std;

   class Integer {         // No default constructor
   public:
      Integer( int x ) : val( x ) {}
      int get( ) { return val; }
   private:
      int val;
   };

int main( )
{
   const int N = 10;
   Integer val ( 25 );
   Integer* Array = ( Integer* ) malloc( N * sizeof( int ) );
   uninitialized_fill( Array, Array + N, val );
   int i;
   cout << "The initialized Array contains: ";
      for ( i = 0 ; i < N; i++ )
      {
         cout << Array [ i ].get( ) << " ";
      }
   cout << endl;
}
  

요구 사항

헤더 <memory>

네임스페이스: std