一的取消引用运算符用于实现原始存储的迭代器表达式*ii = x。
raw_storage_iterator<ForwardIterator, Type>& operator*( );
返回值
对原始存储的迭代器的引用
备注
ForwardIterator 的要求是原始存储的迭代器必须满足要求只表达式*ii = t 为有效的,它的任何内容都不提供有关 operator 或 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;
}
要求
标头: <memory>
命名空间: std