Skip to content

Commit

Permalink
Extract header qswap.h from qglobal.h
Browse files Browse the repository at this point in the history
And move qSwap() docs from qalgorithms.qdoc to qswap.qdoc.

Task-number: QTBUG-99313
Change-Id: I2385d5162a8dbb2de51a0c0509eced77b6a17159
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
Sona Kurazyan committed Aug 25, 2022
1 parent 8aefcd4 commit 9c706e2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 47 deletions.
1 change: 1 addition & 0 deletions src/corelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ qt_internal_add_module(Core
global/qoverload.h
global/qprocessordetection.h
global/qrandom.cpp global/qrandom.h global/qrandom_p.h
global/qswap.h
global/qsysinfo.h
global/qsystemdetection.h
global/qtclasshelpermacros.h
Expand Down
36 changes: 1 addition & 35 deletions src/corelib/global/qglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,41 +136,6 @@ typedef void (*QFunctionPointer)();
# define Q_UNIMPLEMENTED() qWarning("Unimplemented code.")
#endif

QT_WARNING_PUSH
// warning: noexcept-expression evaluates to 'false' because of a call to 'void swap(..., ...)'
QT_WARNING_DISABLE_GCC("-Wnoexcept")

namespace QtPrivate
{
namespace SwapExceptionTester { // insulate users from the "using std::swap" below
using std::swap; // import std::swap
template <typename T>
void checkSwap(T &t)
noexcept(noexcept(swap(t, t)));
// declared, but not implemented (only to be used in unevaluated contexts (noexcept operator))
}
} // namespace QtPrivate

// Documented in ../tools/qalgorithm.qdoc
template <typename T>
constexpr void qSwap(T &value1, T &value2)
noexcept(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1)))
{
using std::swap;
swap(value1, value2);
}

// pure compile-time micro-optimization for our own headers, so not documented:
template <typename T>
constexpr inline void qt_ptr_swap(T* &lhs, T* &rhs) noexcept
{
T *tmp = lhs;
lhs = rhs;
rhs = tmp;
}

QT_WARNING_POP

Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment) Q_ALLOC_SIZE(1);
Q_CORE_EXPORT void *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment) Q_ALLOC_SIZE(2);
Q_CORE_EXPORT void qFreeAligned(void *ptr);
Expand Down Expand Up @@ -219,6 +184,7 @@ QT_END_NAMESPACE
#include <QtCore/qminmax.h>
#include <QtCore/qnumeric.h>
#include <QtCore/qoverload.h>
#include <QtCore/qswap.h>
#include <QtCore/qtdeprecationmarkers.h>
#include <QtCore/qtranslation.h>
#include <QtCore/qtresource.h>
Expand Down
54 changes: 54 additions & 0 deletions src/corelib/global/qswap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QSWAP_H
#define QSWAP_H

#include <QtCore/qtconfigmacros.h>
#include <QtCore/qcompilerdetection.h>

#if 0
#pragma qt_class(QtSwap)
#pragma qt_sync_stop_processing
#endif

QT_BEGIN_NAMESPACE

QT_WARNING_PUSH
// warning: noexcept-expression evaluates to 'false' because of a call to 'void swap(..., ...)'
QT_WARNING_DISABLE_GCC("-Wnoexcept")

namespace QtPrivate
{
namespace SwapExceptionTester { // insulate users from the "using std::swap" below
using std::swap; // import std::swap
template <typename T>
void checkSwap(T &t)
noexcept(noexcept(swap(t, t)));
// declared, but not implemented (only to be used in unevaluated contexts (noexcept operator))
}
} // namespace QtPrivate

// Documented in ../tools/qalgorithm.qdoc
template <typename T>
constexpr void qSwap(T &value1, T &value2)
noexcept(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1)))
{
using std::swap;
swap(value1, value2);
}

// pure compile-time micro-optimization for our own headers, so not documented:
template <typename T>
constexpr inline void qt_ptr_swap(T* &lhs, T* &rhs) noexcept
{
T *tmp = lhs;
lhs = rhs;
rhs = tmp;
}

QT_WARNING_POP

QT_END_NAMESPACE

#endif // QSWAP_H
14 changes: 14 additions & 0 deletions src/corelib/global/qswap.qdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*! \fn template <typename T> void qSwap(T &var1, T &var2)
\relates <QtSwap>
\deprecated

Use \c std::swap instead.

Exchanges the values of variables \a var1 and \a var2.

Example:
\snippet code/doc_src_qalgorithms.cpp 0
*/
12 changes: 0 additions & 12 deletions src/corelib/tools/qalgorithms.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@
\sa {container classes}, <QtGlobal>
*/

/*! \fn template <typename T> void qSwap(T &var1, T &var2)
\relates <QtAlgorithms>
\deprecated

Use \c std::swap instead.

Exchanges the values of variables \a var1 and \a var2.

Example:
\snippet code/doc_src_qalgorithms.cpp 0
*/

/*!
\fn template <typename ForwardIterator> void qDeleteAll(ForwardIterator begin, ForwardIterator end)
\relates <QtAlgorithms>
Expand Down

0 comments on commit 9c706e2

Please sign in to comment.