<QtSwap> | Qt Core | Qt 6.11.1
Description: Swapping the values of two variables.

- Qt 6.11
- Qt Core
- <QtSwap>
- Qt 6.11.1 Reference Documentation

# <QtSwap>

Swapping the values of two variables. More...

Header: | `#include <QtSwap>`

## Functions

void | qSwap(T &lhs, T &rhs)

## Detailed Description

## Function Documentation

### `[constexpr noexcept(...)]` template <typename T> void qSwap(T &lhs, T &rhs)

Exchanges the values of variables lhs and rhs, taking type-specific `swap()` overloads into account.

This function is Qt's version of `boost::swap()`, and is equivalent to

     using std::swap;   // bring std::swap into scope (for built-in types)
     swap(lhs, rhs);    // unqualified call (picks up type-specific overloads
                        // via Argument-Dependent Lookup, or falls back to std::swap)

Use this function primarily in generic code, where you would traditionally have written the above two lines, because you don't know anything about `T`.

If you already know what `T` is, then use one of the following options, in order of preference:

- `lhs.swap(rhs);` if such a member-swap exists
- `std::swap(lhs, rhs);` if no type-specific `swap()` exists

See `boost::swap()` on boost.org for more details.

See also `std::swap` on cppreference.com, `Swappable` on cppreference.com.

Note: This function is noexcept when `std::is_nothrow_swappable_v<T>` is `true`.