Files
cppdraft_translate/cppdraft/utility/swap.md
2025-10-25 03:02:53 +03:00

2.4 KiB

[utility.swap]

22 General utilities library [utilities]

22.2 Utility components [utility]

22.2.2 swap [utility.swap]

🔗

template<class T> constexpr void swap(T& a, T& b) noexcept(see below);

1

#

Constraints: is_move_constructible_v is true andis_move_assignable_v is true.

2

#

Preconditions: TypeT meets theCpp17MoveConstructible (Table 31) andCpp17MoveAssignable (Table 33) requirements.

3

#

Effects: Exchanges values stored in two locations.

4

#

Remarks: The exception specification is equivalent to:is_nothrow_move_constructible_v && is_nothrow_move_assignable_v

🔗

template<class T, size_t N> constexpr void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>);

5

#

Constraints: is_swappable_v is true.

6

#

Preconditions: a[i] is swappable with ([swappable.requirements]) b[i] for all i in the range [0, N).

7

#

Effects: As if by swap_ranges(a, a + N, b).