Namespaces
Variants
Views
Actions

std::swap

From cppreference.com
 
 
 
Defined in header <algorithm>
Defined in header <utility>
(until C++11)
(since C++11)
template< class T >
void swap( T& a, T& b );
(1)
template< class T, size_t N >
void swap( T (&a)[N], T (&b)[N]);
(2) (since C++11)

Exchanges the given values.

1) Swaps the values a and b.

2) Swaps the arrays a and b. In effect calls std::swap_ranges(a, a+N, b).

Contents

[edit] Parameters

a, b - the values to be swapped

[edit] Return value

(none)

[edit] Exceptions

1) noexcept specification:  (since C++11)

noexcept(noexcept(

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

))

2) noexcept specification:  (since C++11)

noexcept(noexcept(swap(*a, *b)))

[edit] Complexity

Constant

[edit] Specializations

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

specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap() algorithm
(function template)
specializes the std::swap() algorithm
(function template)
specializes the std::swap() algorithm
(function template)
specializes the std::swap() algorithm
(function template)
specializes the std::swap() algorithm
(function template)
specializes the std::swap() algorithm
(function template)
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap() algorithm
(function template)
specializes the std::swap() algorithm
(function template)
specializes the std::swap algorithm
(function template) [edit]
specializes the std::swap() algorithm
(function template)
specializes the std::swap() algorithm
(function template)
specializes the std::swap() algorithm
(function template)

[edit] Example

[edit] See also

swaps the elements pointed to by two iterators
(function template) [edit]
swaps two ranges of elements
(function template) [edit]