一个取消引用运算符的用于实现的原始存储表达式迭代器 *ii = x。
raw_storage_iterator<ForwardIterator, Type>& operator*( );
返回值
对迭代器的原始存储的引用
备注
ForwardIterator 的要求是的原始存储必须满足迭代器只需要表达式 *ii t = 有效,并将任何自己不提供有关 运算符 或 operator=。 此实现的成员运算符返回 *this,因此,类型&)。operator=(const 表达式可执行实际存储,如 *_Ptr = _Val。
示例
// 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;
}
要求
页眉: <内存>
命名空间: std