list::operator=

Replaces the elements of the list with a copy of another list.

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

Parameters

Parameter

Description

_Right

The list Class being copied into the list.

Remarks

After erasing any existing elements in a list, the operator either copies or moves the contents of _Right into the list.

Example

// 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;
}

Output

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

Requirements

Header: <list>

Namespace: std

See Also

Reference

list Class

Standard Template Library