Namespaces
Variants
Views
Actions

std::swap

From cppreference.com
< cpp‎ | algorithm
Revision as of 10:20, 10 October 2011 by P12bot (Talk | contribs)

Template:cpp/algorithm/sidebar Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <algorithm>
Defined in header <utility>
</td>

<td></td>

<td>
Template:mark pre c++11 version
Template:mark c++11 version
</td>

</tr> <tr class="t-dcl ">

<td >
template< class T >
void swap( T& a, T& b );
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class T, size_t N >
void swap( T (&a)[N], T (&b)[N]);
</td>

<td > (2) </td> <td > Template:mark c++11 feature </td> </tr> Template:ddcl list end

Exchanges the given values.

1) Swaps the values a and b.

2) Swaps the arrays a and b. In effect calls Template:cpp.

Contents

Parameters

a, b - the values to be swapped

Return value

Template:return none

Exceptions

1)
noexcept specification:  
noexcept(noexcept(

    std::is_nothrow_move_constructible<T>::value &&
    std::is_nothrow_move_assignable<T>::value

))
2)
noexcept specification:  
noexcept(noexcept(swap(*a, *b)))

Complexity

Constant

Specializations

Custom specializations of the Template:cpp algorithm are allowed. The following specializations are already provided by the standard library:

Template:cpp/utility/pair/dcl list std swapTemplate:cpp/utility/tuple/dcl list std swapTemplate:cpp/memory/shared ptr/dcl list std swapTemplate:cpp/memory/unique ptr/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/container/dcl list std swapTemplate:cpp/thread/thread/dcl list std swap
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)
specializes the Template:cpp/ltf algorithm
(function template)

Example

Template:example cpp

See also

Template:cpp/algorithm/dcl list iter swapTemplate:cpp/algorithm/dcl list swap ranges