Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qswap.qdoc
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \fn template <typename T> void qSwap(T &lhs, T &rhs)
6 \relates <QtSwap>
7
8 Exchanges the values of variables \a lhs and \a rhs,
9 taking type-specific \c{swap()} overloads into account.
10
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()}},
13 and is equivalent to
14 \code
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)
18 \endcode
19
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}.
22
23 If you already know what \c{T} is, then use one of the following options, in
24 order of preference:
25
26 \list
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
29 \endlist
30
31 See
32 \l{https://www.boost.org/doc/libs/release/libs/core/doc/html/core/swap.html}{\c{boost::swap()} on boost.org}
33 for more details.
34
35 See also
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}.
38*/