diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index aed5fd973a2..1bd01cd30cc 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -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 diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 0ebbc34f499..09072b8b6db 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -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 - 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 -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 -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); @@ -219,6 +184,7 @@ QT_END_NAMESPACE #include #include #include +#include #include #include #include diff --git a/src/corelib/global/qswap.h b/src/corelib/global/qswap.h new file mode 100644 index 00000000000..9ff6c7d9c58 --- /dev/null +++ b/src/corelib/global/qswap.h @@ -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 +#include + +#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 + 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 +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 +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 diff --git a/src/corelib/global/qswap.qdoc b/src/corelib/global/qswap.qdoc new file mode 100644 index 00000000000..2d9d56b694b --- /dev/null +++ b/src/corelib/global/qswap.qdoc @@ -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 void qSwap(T &var1, T &var2) + \relates + \deprecated + + Use \c std::swap instead. + + Exchanges the values of variables \a var1 and \a var2. + + Example: + \snippet code/doc_src_qalgorithms.cpp 0 +*/ diff --git a/src/corelib/tools/qalgorithms.qdoc b/src/corelib/tools/qalgorithms.qdoc index 4a9c03a43c6..5fe0b3e8c3a 100644 --- a/src/corelib/tools/qalgorithms.qdoc +++ b/src/corelib/tools/qalgorithms.qdoc @@ -109,18 +109,6 @@ \sa {container classes}, */ -/*! \fn template void qSwap(T &var1, T &var2) - \relates - \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 void qDeleteAll(ForwardIterator begin, ForwardIterator end) \relates