std::swap

From Cppreference

Jump to: navigation, search
Defined in header <algorithm>
Defined in header <utility>
(pre-C++11 version)
(C++11 version)

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) (C++11 feature)

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:  (C++11 feature)

noexcept(noexcept(

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

))

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

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

[edit] Example

[edit] Complexity

constant

[edit] See also

iter_swap
swaps the elements pointed to by two iterators
(function template)
swap_ranges
swaps two ranges of elements
(function template)
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox
In other languages