共用方式為


list::swap (STL/CLR)

交換兩個容器的內容。

    void swap(list<Value>% right);

參數

  • right
    要交換內容的容器。

備註

成員函式會交換受控制的序列之間*this和right。 它會固定的時間,就會擲回任何例外狀況。 您可以用它做為交換兩個容器的內容的快速方法。

範例

// cliext_list_swap.cpp 
// compile with: /clr 
#include <cliext/list> 
 
int main() 
    { 
    cliext::list<wchar_t> c1; 
    c1.push_back(L'a'); 
    c1.push_back(L'b'); 
    c1.push_back(L'c'); 
 
// display initial contents " a b c" 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
 
// construct another container with repetition of values 
    cliext::list<wchar_t> c2(5, L'x'); 
    for each (wchar_t elem in c2) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
 
// swap and redisplay 
    c1.swap(c2); 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
 
    for each (wchar_t elem in c2) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
    return (0); 
    } 
 
  

需求

標頭: < cliext/清單 >

Namespace: cliext

請參閱

參考

list (STL/CLR)

list::assign (STL/CLR)

list::operator= (STL/CLR)