Extract header qswap.h from qglobal.h

And move qSwap() docs from qalgorithms.qdoc to qswap.qdoc.

Task-number: QTBUG-99313
Change-Id: I2385d5162a8dbb2de51a0c0509eced77b6a17159
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Sona Kurazyan 2022-08-22 11:44:01 +02:00
parent 8aefcd4756
commit 9c706e2567
5 changed files with 70 additions and 47 deletions

View File

@ -73,6 +73,7 @@ qt_internal_add_module(Core
global/qoverload.h global/qoverload.h
global/qprocessordetection.h global/qprocessordetection.h
global/qrandom.cpp global/qrandom.h global/qrandom_p.h global/qrandom.cpp global/qrandom.h global/qrandom_p.h
global/qswap.h
global/qsysinfo.h global/qsysinfo.h
global/qsystemdetection.h global/qsystemdetection.h
global/qtclasshelpermacros.h global/qtclasshelpermacros.h

View File

@ -136,41 +136,6 @@ typedef void (*QFunctionPointer)();
# define Q_UNIMPLEMENTED() qWarning("Unimplemented code.") # define Q_UNIMPLEMENTED() qWarning("Unimplemented code.")
#endif #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 *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 *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment) Q_ALLOC_SIZE(2);
Q_CORE_EXPORT void qFreeAligned(void *ptr); Q_CORE_EXPORT void qFreeAligned(void *ptr);
@ -219,6 +184,7 @@ QT_END_NAMESPACE
#include <QtCore/qminmax.h> #include <QtCore/qminmax.h>
#include <QtCore/qnumeric.h> #include <QtCore/qnumeric.h>
#include <QtCore/qoverload.h> #include <QtCore/qoverload.h>
#include <QtCore/qswap.h>
#include <QtCore/qtdeprecationmarkers.h> #include <QtCore/qtdeprecationmarkers.h>
#include <QtCore/qtranslation.h> #include <QtCore/qtranslation.h>
#include <QtCore/qtresource.h> #include <QtCore/qtresource.h>

View File

@ -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

View File

@ -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
*/

View File

@ -109,18 +109,6 @@
\sa {container classes}, <QtGlobal> \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) \fn template <typename ForwardIterator> void qDeleteAll(ForwardIterator begin, ForwardIterator end)
\relates <QtAlgorithms> \relates <QtAlgorithms>