Share via


raw_storage_iterator::operator*

A dereferencing operator used to implement the raw storage iterator expression *ii = x.

raw_storage_iterator<ForwardIterator, Type>& operator*( );

Return Value

A reference to the raw storage iterator

Remarks

The requirements for a ForwardIterator are that the raw storage iterator must satisfy require only the expression *ii = t be valid and that it says nothing about the operator or the operator= on their own. The member operators in this implementation returns *this, so that operator=(const Type&) can perform the actual store in an expression, such as *_Ptr = _Val.

Example

// raw_storage_iterator_op_deref.cpp
// compile with: /EHsc
#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 << "Not constructed.\n";
      cout << "Copying " << i << endl;  
      x = i; 
      return *this;
   };

   int x;

private:
   bool bIsConstructed;
};

int main( void) 
{
   Int *pInt = ( Int* ) malloc( sizeof( Int ) );
   memset( pInt, 0, sizeof( Int ) ); // Set bIsConstructed to false;
   *pInt = 5;
   raw_storage_iterator< Int*, Int > it( pInt );
   *it = 5;
}
Not constructed.
Copying 5
Constructing 5

Requirements

Header: <memory>

Namespace: std

See Also

Reference

raw_storage_iterator Class