raw_storage_iterator


An iterator used to directly construct objects in raw storage.

Library

Standards<ToolKit>

Declaration


#include <memory>

template< class OutputIterator, class T >
class raw_storage_iterator : public output_iterator

Interface

Constructor
explicit raw_storage_iterator( OutputIterator iterator )
Constructs a raw storage iterator associated with iterator .
*
raw_storage_iterator< OutputIterator, T >& operator *()
Returns a reference to the raw storage iterator.
=
raw_storage_iterator< OutputIterator, T >& operator=( const T& other )
Constructs a copy of other using the raw storage iterator's associated iterator.
++
raw_storage_iterator< OutputIterator, T >& operator++()
Advances the raw storage iterator's associated iterator.
++
raw_storage_iterator< OutputIterator, T > operator++( int )
Advances the raw storage iterator's associated iterator.
Example <ospace/osstd/examples/rawiter.cpp>
#include <iostream>
#include <memory>

class X
  {
  public:
    X( int i = 0 ) : i_( i ) {}
    operator int() const { return i_; }

  private:
    int i_;
  };

inline ostream&
operator<<( ostream& stream, const X& x )
  {
  return stream << "X( " << (int)x << " )";
  }


void
main()
  {
  allocator< X > a;

  // Allocate( but do not construct ) storage for 5 elements.
  const int limit = 5;
  X* p = a.allocate( limit );

  // Construct elements in raw memory.
  raw_storage_iterator< X*, X > r( p );

  int i;
  for ( i = 0; i < limit; ++i )
    *r++ = X( i );

  // Use newly constructed objects.
  X* p2 = p;
  for ( i = 0; i < limit; ++i )
    cout << *p2++ << "\n";

  // Call all destructors, then free memory.
  destroy( p, p + limit );
  a.deallocate( p );
  }

0
1
2
3
4

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.