raw_storage_iterator::operator=

赋值运算符用于实现原始存储的迭代器表达式存储的*i = x 在内存中。

raw_storage_iterator<ForwardIterator, Type>& operator=(
   const Type& _Val
);

参数

  • _Val
    类型要插入的 *** 类型 *** 对象的值到内存中。

返回值

运算符插入 _Val 到内存中,然后返回对原始存储的迭代器。

备注

ForwardIterator 的要求,指出原始存储的迭代器必须满足要求只表达式*ii = t 为有效的,因此,它的任何内容都不提供有关 operatoroperator=。这些成员运算符返回 *this

赋值运算符首先构造在输出序列下使用对象存储的迭代器值,通过计算位置新的表达式 新建 (void *) &*first) *** 类型 ***(_Val)。

示例

// raw_storage_iterator_op_assign.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

请参见

参考

raw_storage_iterator Class