1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5 \fn template <typename T> void qSwap(T &lhs, T &rhs)
8 Exchanges the values of variables \a lhs and \a rhs,
9 taking type-specific \c{swap()} overloads into account.
11 This function is Qt's version of
12 \l{https://www.boost.org/doc/libs/release/libs/core/doc/html/core/swap.html}{\c{boost::swap()}},
15 using std::swap; // bring std::swap into scope (for built-in types)
16 swap(lhs, rhs); // unqualified call (picks up type-specific overloads
17 // via Argument-Dependent Lookup, or falls back to std::swap)
20 Use this function primarily in generic code, where you would traditionally
21 have written the above two lines, because you don't know anything about \c{T}.
23 If you already know what \c{T} is, then use one of the following options, in
27 \li \c{lhs.swap(rhs);} if such a member-swap exists
28 \li \c{std::swap(lhs, rhs);} if no type-specific \c{swap()} exists
32 \l{https://www.boost.org/doc/libs/release/libs/core/doc/html/core/swap.html}{\c{boost::swap()} on boost.org}
36 \l{https://en.cppreference.com/w/cpp/algorithm/swap}{\c{std::swap} on cppreference.com},
37 \l{https://en.cppreference.com/w/cpp/named_req/Swappable}{\c{Swappable} on cppreference.com}.