raw_storage_iterator::raw_storage_iterator
建構函式使用指定的基礎輸出 Iterator 的未經處理的儲存體 Iterator。
explicit raw_storage_iterator(
ForwardIterator _First
);
參數
- _First
正向是基礎建構之 raw_storage_iterator 物件的列舉值。
範例
// raw_storage_iterator_ctor.cpp
// compile with: /EHsc /W3
#include <iostream>
#include <iterator>
#include <memory>
#include <list>
using namespace std;
class Int
{
public:
Int(int i)
{
cout << "Constructing " << i << endl;
x = i;
bIsConstructed = true;
};
Int &operator=( int i )
{
if (!bIsConstructed)
cout << "Error! I'm not constructed!\n";
cout << "Copying " << i << endl; x = i; return *this;
};
int x;
bool bIsConstructed;
};
int main( void )
{
std::list<int> l;
l.push_back( 1 );
l.push_back( 2 );
l.push_back( 3 );
l.push_back( 4 );
Int *pInt = (Int*)malloc(sizeof(Int)*l.size( ));
memset (pInt, 0, sizeof(Int)*l.size( ));
// Hack: make sure bIsConstructed is false
std::copy( l.begin( ), l.end( ), pInt ); // C4996
for (unsigned int i = 0; i < l.size( ); i++)
cout << "array " << i << " = " << pInt[i].x << endl;;
memset (pInt, 0, sizeof(Int)*l.size( ));
// hack: make sure bIsConstructed is false
std::copy( l.begin( ), l.end( ),
std::raw_storage_iterator<Int*,Int>(pInt)); // C4996
for (unsigned int i = 0; i < l.size( ); i++ )
cout << "array " << i << " = " << pInt[i].x << endl;
free(pInt);
}
需求
標頭: <memory>
命名空間: std