1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSWAP_H
5#define QSWAP_H
6
7#include <QtCore/qtconfigmacros.h>
8#include <QtCore/qcompilerdetection.h>
9
10#if 0
11#pragma qt_class(QtSwap)
12#pragma qt_sync_stop_processing
13#endif
14
15QT_BEGIN_NAMESPACE
16
17QT_WARNING_PUSH
18// warning: noexcept-expression evaluates to 'false' because of a call to 'void swap(..., ...)'
19QT_WARNING_DISABLE_GCC("-Wnoexcept")
20
21namespace QtPrivate
22{
23namespace SwapExceptionTester { // insulate users from the "using std::swap" below
24 using std::swap; // import std::swap
25 template <typename T>
26 void checkSwap(T &t)
27 noexcept(noexcept(swap(t, t)));
28 // declared, but not implemented (only to be used in unevaluated contexts (noexcept operator))
29}
30} // namespace QtPrivate
31
32// Documented in ../tools/qalgorithm.qdoc
33template <typename T>
34constexpr void qSwap(T &value1, T &value2)
35 noexcept(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1)))
36{
37 using std::swap;
38 swap(value1, value2);
39}
40
41// pure compile-time micro-optimization for our own headers, so not documented:
42template <typename T>
43constexpr inline void qt_ptr_swap(T* &lhs, T* &rhs) noexcept
44{
45 T *tmp = lhs;
46 lhs = rhs;
47 rhs = tmp;
48}
49
50QT_WARNING_POP
51
52QT_END_NAMESPACE
53
54#endif // QSWAP_H
55

source code of qtbase/src/corelib/global/qswap.h