swap [C++ Reference]
Keywords: stl,deque,swap
Date: 2009-09-25T08:05:18-0700

[[swap]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## swap

Syntax:

        #include <deque>
        void swap( container& from );

The swap() function exchanges the elements of the current deque with those of from. This function operates in constant time.

For example, the following code uses the swap() function to exchange the values of two deques:

        deque<int> v( 5, 1 );
        deque<int> d( 4, 42 );
        v.swap( d );

        size_t i;
        cout << "v contains: ";
        for( i = 0; i < v.size(); ++i ) cout << v[i] << ' ';
        cout << '\n';

        cout << "d contains: ";
        for( i = 0; i < d.size(); ++i ) cout << d[i] << ' ';
        cout << '\n';

The above code displays:

        v contains: 42 42 42 42
        d contains: 1 1 1 1 1

Related Topics: insert, operator =

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •