Share via


list::operator=

別のリストのコピーでリストの要素を置き換えます。

list& operator=(
   const list& _Right
);
list& operator=(
   list&& _Right
);

パラメーター

パラメーター

説明

_Right

list にコピーする list クラス

解説

list 内の既存の要素を消去した後、この演算子は _Right の内容を list 内にコピーまたは移動します。

使用例

// list_operator_as.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( )
{
   using namespace std;
   list<int> v1, v2, v3;
   list<int>::iterator iter;

   v1.push_back(10);
   v1.push_back(20);
   v1.push_back(30);
   v1.push_back(40);
   v1.push_back(50);

   cout << "v1 = " ;
   for (iter = v1.begin(); iter != v1.end(); iter++)
      cout << *iter << " ";
   cout << endl;

   v2 = v1;
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << *iter << " ";
   cout << endl;

// move v1 into v2
   v2.clear();
   v2 = forward< list<int> >(v1);
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << *iter << " ";
   cout << endl;
}

出力

v1 = 10 20 30 40 50 
v2 = 10 20 30 40 50 
v2 = 10 20 30 40 50 

必要条件

ヘッダー: <list>

名前空間: std

参照

関連項目

list クラス

標準テンプレート ライブラリ