list::swap (STL/CLR)

Swaps the contents of two containers.

    void swap(list<Value>% right);

right

Container to swap contents with.

The member function swaps the controlled sequences between *this and right. It does so in constant time and it throws no exceptions. You use it as a quick way to exchange the contents of two containers.

// 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); 
    } 
 
a b c x x x x x x x x x x a b c

Header: <cliext/list>

Namespace: cliext

Community Additions

ADD
Show: