Extract header qoverload.h from qglobal.h
Task-number: QTBUG-99313 Change-Id: Id827f95b5aa5d4e0d57dcc1060a0746bcaa34db3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
19454b05c2
commit
ff8de321e2
@ -62,6 +62,7 @@ qt_internal_add_module(Core
|
|||||||
global/qnativeinterface.h global/qnativeinterface_p.h
|
global/qnativeinterface.h global/qnativeinterface_p.h
|
||||||
global/qnumeric.cpp global/qnumeric.h global/qnumeric_p.h
|
global/qnumeric.cpp global/qnumeric.h global/qnumeric_p.h
|
||||||
global/qoperatingsystemversion.cpp global/qoperatingsystemversion.h global/qoperatingsystemversion_p.h
|
global/qoperatingsystemversion.cpp global/qoperatingsystemversion.h global/qoperatingsystemversion_p.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/qsysinfo.h
|
global/qsysinfo.h
|
||||||
|
@ -1217,57 +1217,6 @@ static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
|
|||||||
\sa qMin(), qMax()
|
\sa qMin(), qMax()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*! \fn template <typename T> auto qOverload(T functionPointer)
|
|
||||||
\relates <QtGlobal>
|
|
||||||
\since 5.7
|
|
||||||
|
|
||||||
Returns a pointer to an overloaded function. The template
|
|
||||||
parameter is the list of the argument types of the function.
|
|
||||||
\a functionPointer is the pointer to the (member) function:
|
|
||||||
|
|
||||||
\snippet code/src_corelib_global_qglobal.cpp 52
|
|
||||||
|
|
||||||
If a member function is also const-overloaded \l qConstOverload and
|
|
||||||
\l qNonConstOverload need to be used.
|
|
||||||
|
|
||||||
qOverload() requires C++14 enabled. In C++11-only code, the helper
|
|
||||||
classes QOverload, QConstOverload, and QNonConstOverload can be used directly:
|
|
||||||
|
|
||||||
\snippet code/src_corelib_global_qglobal.cpp 53
|
|
||||||
|
|
||||||
\note Qt detects the necessary C++14 compiler support by way of the feature
|
|
||||||
test recommendations from
|
|
||||||
\l{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations}
|
|
||||||
{C++ Committee's Standing Document 6}.
|
|
||||||
|
|
||||||
\sa qConstOverload(), qNonConstOverload(), {Differences between String-Based
|
|
||||||
and Functor-Based Connections}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*! \fn template <typename T> auto qConstOverload(T memberFunctionPointer)
|
|
||||||
\relates <QtGlobal>
|
|
||||||
\since 5.7
|
|
||||||
|
|
||||||
Returns the \a memberFunctionPointer pointer to a constant member function:
|
|
||||||
|
|
||||||
\snippet code/src_corelib_global_qglobal.cpp 54
|
|
||||||
|
|
||||||
\sa qOverload, qNonConstOverload, {Differences between String-Based
|
|
||||||
and Functor-Based Connections}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*! \fn template <typename T> auto qNonConstOverload(T memberFunctionPointer)
|
|
||||||
\relates <QtGlobal>
|
|
||||||
\since 5.7
|
|
||||||
|
|
||||||
Returns the \a memberFunctionPointer pointer to a non-constant member function:
|
|
||||||
|
|
||||||
\snippet code/src_corelib_global_qglobal.cpp 54
|
|
||||||
|
|
||||||
\sa qOverload, qNonConstOverload, {Differences between String-Based
|
|
||||||
and Functor-Based Connections}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\macro QT_VERSION_CHECK(major, minor, patch)
|
\macro QT_VERSION_CHECK(major, minor, patch)
|
||||||
\relates <QtGlobal>
|
\relates <QtGlobal>
|
||||||
|
@ -1213,62 +1213,6 @@ template <typename Ptr> inline auto qGetPtrHelper(Ptr &ptr) noexcept -> decltype
|
|||||||
#define Q_D(Class) Class##Private * const d = d_func()
|
#define Q_D(Class) Class##Private * const d = d_func()
|
||||||
#define Q_Q(Class) Class * const q = q_func()
|
#define Q_Q(Class) Class * const q = q_func()
|
||||||
|
|
||||||
#ifdef Q_QDOC
|
|
||||||
// Just for documentation generation
|
|
||||||
template<typename T>
|
|
||||||
auto qOverload(T functionPointer);
|
|
||||||
template<typename T>
|
|
||||||
auto qConstOverload(T memberFunctionPointer);
|
|
||||||
template<typename T>
|
|
||||||
auto qNonConstOverload(T memberFunctionPointer);
|
|
||||||
#else
|
|
||||||
template <typename... Args>
|
|
||||||
struct QNonConstOverload
|
|
||||||
{
|
|
||||||
template <typename R, typename T>
|
|
||||||
constexpr auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr)
|
|
||||||
{ return ptr; }
|
|
||||||
|
|
||||||
template <typename R, typename T>
|
|
||||||
static constexpr auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr)
|
|
||||||
{ return ptr; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
struct QConstOverload
|
|
||||||
{
|
|
||||||
template <typename R, typename T>
|
|
||||||
constexpr auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr)
|
|
||||||
{ return ptr; }
|
|
||||||
|
|
||||||
template <typename R, typename T>
|
|
||||||
static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr)
|
|
||||||
{ return ptr; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
|
|
||||||
{
|
|
||||||
using QConstOverload<Args...>::of;
|
|
||||||
using QConstOverload<Args...>::operator();
|
|
||||||
using QNonConstOverload<Args...>::of;
|
|
||||||
using QNonConstOverload<Args...>::operator();
|
|
||||||
|
|
||||||
template <typename R>
|
|
||||||
constexpr auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr)
|
|
||||||
{ return ptr; }
|
|
||||||
|
|
||||||
template <typename R>
|
|
||||||
static constexpr auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr)
|
|
||||||
{ return ptr; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... Args> constexpr inline QOverload<Args...> qOverload = {};
|
|
||||||
template <typename... Args> constexpr inline QConstOverload<Args...> qConstOverload = {};
|
|
||||||
template <typename... Args> constexpr inline QNonConstOverload<Args...> qNonConstOverload = {};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
class QByteArray;
|
class QByteArray;
|
||||||
Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
|
Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
|
||||||
// need it as two functions because QString is only forward-declared here
|
// need it as two functions because QString is only forward-declared here
|
||||||
@ -1290,13 +1234,6 @@ Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nu
|
|||||||
"Compile your code with -fPIC (and not with -fPIE)."
|
"Compile your code with -fPIC (and not with -fPIE)."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define QT_VA_ARGS_CHOOSE(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
|
|
||||||
#define QT_VA_ARGS_EXPAND(...) __VA_ARGS__ // Needed for MSVC
|
|
||||||
#define QT_VA_ARGS_COUNT(...) QT_VA_ARGS_EXPAND(QT_VA_ARGS_CHOOSE(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
|
|
||||||
#define QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC) MACRO##_##ARGC
|
|
||||||
#define QT_OVERLOADED_MACRO_IMP(MACRO, ARGC) QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC)
|
|
||||||
#define QT_OVERLOADED_MACRO(MACRO, ...) QT_VA_ARGS_EXPAND(QT_OVERLOADED_MACRO_IMP(MACRO, QT_VA_ARGS_COUNT(__VA_ARGS__))(__VA_ARGS__))
|
|
||||||
|
|
||||||
// This macro can be used to calculate member offsets for types with a non standard layout.
|
// This macro can be used to calculate member offsets for types with a non standard layout.
|
||||||
// It uses the fact that offsetof() is allowed to support those types since C++17 as an optional
|
// It uses the fact that offsetof() is allowed to support those types since C++17 as an optional
|
||||||
// feature. All our compilers do support this, but some issue a warning, so we wrap the offsetof()
|
// feature. All our compilers do support this, but some issue a warning, so we wrap the offsetof()
|
||||||
@ -1322,6 +1259,7 @@ QT_END_NAMESPACE
|
|||||||
#include <QtCore/qforeach.h>
|
#include <QtCore/qforeach.h>
|
||||||
#include <QtCore/qglobalstatic.h>
|
#include <QtCore/qglobalstatic.h>
|
||||||
#include <QtCore/qnumeric.h>
|
#include <QtCore/qnumeric.h>
|
||||||
|
#include <QtCore/qoverload.h>
|
||||||
#include <QtCore/qtranslation.h>
|
#include <QtCore/qtranslation.h>
|
||||||
#include <QtCore/qversiontagging.h>
|
#include <QtCore/qversiontagging.h>
|
||||||
|
|
||||||
|
75
src/corelib/global/qoverload.h
Normal file
75
src/corelib/global/qoverload.h
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
// 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 QOVERLOAD_H
|
||||||
|
#define QOVERLOAD_H
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#pragma qt_class(QOverload)
|
||||||
|
#pragma qt_sync_stop_processing
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef Q_QDOC
|
||||||
|
// Just for documentation generation
|
||||||
|
template<typename T>
|
||||||
|
auto qOverload(T functionPointer);
|
||||||
|
template<typename T>
|
||||||
|
auto qConstOverload(T memberFunctionPointer);
|
||||||
|
template<typename T>
|
||||||
|
auto qNonConstOverload(T memberFunctionPointer);
|
||||||
|
#else
|
||||||
|
template <typename... Args>
|
||||||
|
struct QNonConstOverload
|
||||||
|
{
|
||||||
|
template <typename R, typename T>
|
||||||
|
constexpr auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr)
|
||||||
|
{ return ptr; }
|
||||||
|
|
||||||
|
template <typename R, typename T>
|
||||||
|
static constexpr auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr)
|
||||||
|
{ return ptr; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
struct QConstOverload
|
||||||
|
{
|
||||||
|
template <typename R, typename T>
|
||||||
|
constexpr auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr)
|
||||||
|
{ return ptr; }
|
||||||
|
|
||||||
|
template <typename R, typename T>
|
||||||
|
static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr)
|
||||||
|
{ return ptr; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
|
||||||
|
{
|
||||||
|
using QConstOverload<Args...>::of;
|
||||||
|
using QConstOverload<Args...>::operator();
|
||||||
|
using QNonConstOverload<Args...>::of;
|
||||||
|
using QNonConstOverload<Args...>::operator();
|
||||||
|
|
||||||
|
template <typename R>
|
||||||
|
constexpr auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr)
|
||||||
|
{ return ptr; }
|
||||||
|
|
||||||
|
template <typename R>
|
||||||
|
static constexpr auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr)
|
||||||
|
{ return ptr; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... Args> constexpr inline QOverload<Args...> qOverload = {};
|
||||||
|
template <typename... Args> constexpr inline QConstOverload<Args...> qConstOverload = {};
|
||||||
|
template <typename... Args> constexpr inline QNonConstOverload<Args...> qNonConstOverload = {};
|
||||||
|
|
||||||
|
#endif // Q_QDOC
|
||||||
|
|
||||||
|
#define QT_VA_ARGS_CHOOSE(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
|
||||||
|
#define QT_VA_ARGS_EXPAND(...) __VA_ARGS__ // Needed for MSVC
|
||||||
|
#define QT_VA_ARGS_COUNT(...) QT_VA_ARGS_EXPAND(QT_VA_ARGS_CHOOSE(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
|
||||||
|
#define QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC) MACRO##_##ARGC
|
||||||
|
#define QT_OVERLOADED_MACRO_IMP(MACRO, ARGC) QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC)
|
||||||
|
#define QT_OVERLOADED_MACRO(MACRO, ...) QT_VA_ARGS_EXPAND(QT_OVERLOADED_MACRO_IMP(MACRO, QT_VA_ARGS_COUNT(__VA_ARGS__))(__VA_ARGS__))
|
||||||
|
|
||||||
|
#endif /* QOVERLOAD_H */
|
53
src/corelib/global/qoverload.qdoc
Normal file
53
src/corelib/global/qoverload.qdoc
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
|
||||||
|
|
||||||
|
/*! \fn template <typename T> auto qOverload(T functionPointer)
|
||||||
|
\relates <QOverload>
|
||||||
|
\since 5.7
|
||||||
|
|
||||||
|
Returns a pointer to an overloaded function. The template
|
||||||
|
parameter is the list of the argument types of the function.
|
||||||
|
\a functionPointer is the pointer to the (member) function:
|
||||||
|
|
||||||
|
\snippet code/src_corelib_global_qglobal.cpp 52
|
||||||
|
|
||||||
|
If a member function is also const-overloaded \l qConstOverload and
|
||||||
|
\l qNonConstOverload need to be used.
|
||||||
|
|
||||||
|
qOverload() requires C++14 enabled. In C++11-only code, the helper
|
||||||
|
classes QOverload, QConstOverload, and QNonConstOverload can be used directly:
|
||||||
|
|
||||||
|
\snippet code/src_corelib_global_qglobal.cpp 53
|
||||||
|
|
||||||
|
\note Qt detects the necessary C++14 compiler support by way of the feature
|
||||||
|
test recommendations from
|
||||||
|
\l{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations}
|
||||||
|
{C++ Committee's Standing Document 6}.
|
||||||
|
|
||||||
|
\sa qConstOverload(), qNonConstOverload(), {Differences between String-Based
|
||||||
|
and Functor-Based Connections}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \fn template <typename T> auto qConstOverload(T memberFunctionPointer)
|
||||||
|
\relates <QOverload>
|
||||||
|
\since 5.7
|
||||||
|
|
||||||
|
Returns the \a memberFunctionPointer pointer to a constant member function:
|
||||||
|
|
||||||
|
\snippet code/src_corelib_global_qglobal.cpp 54
|
||||||
|
|
||||||
|
\sa qOverload, qNonConstOverload, {Differences between String-Based
|
||||||
|
and Functor-Based Connections}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \fn template <typename T> auto qNonConstOverload(T memberFunctionPointer)
|
||||||
|
\relates <QOverload>
|
||||||
|
\since 5.7
|
||||||
|
|
||||||
|
Returns the \a memberFunctionPointer pointer to a non-constant member function:
|
||||||
|
|
||||||
|
\snippet code/src_corelib_global_qglobal.cpp 54
|
||||||
|
|
||||||
|
\sa qOverload, qNonConstOverload, {Differences between String-Based
|
||||||
|
and Functor-Based Connections}
|
||||||
|
*/
|
Loading…
Reference in New Issue
Block a user