raw_storage_iterator::raw_storage_iterator
Erstellt einen unbearbeiteten Speicheriterator mit einem angegebenen zugrunde liegenden Ausgabeiterator.
explicit raw_storage_iterator(
ForwardIterator _First
);
Parameter
- _First
Der Vorwärtsiterator, der dem Objekt raw_storage_iterator, zugrunde zu liegen ist, das erstellt wird.
Beispiel
// 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);
}
Anforderungen
Header: <memory>
Namespace: std