Skip to content

Commit ff8de32

Browse files
author
Sona Kurazyan
committed
Extract header qoverload.h from qglobal.h
Task-number: QTBUG-99313 Change-Id: Id827f95b5aa5d4e0d57dcc1060a0746bcaa34db3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
1 parent 19454b0 commit ff8de32

File tree

5 files changed

+130
-114
lines changed

5 files changed

+130
-114
lines changed

src/corelib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ qt_internal_add_module(Core
6262
global/qnativeinterface.h global/qnativeinterface_p.h
6363
global/qnumeric.cpp global/qnumeric.h global/qnumeric_p.h
6464
global/qoperatingsystemversion.cpp global/qoperatingsystemversion.h global/qoperatingsystemversion_p.h
65+
global/qoverload.h
6566
global/qprocessordetection.h
6667
global/qrandom.cpp global/qrandom.h global/qrandom_p.h
6768
global/qsysinfo.h

src/corelib/global/qglobal.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,57 +1217,6 @@ static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
12171217
\sa qMin(), qMax()
12181218
*/
12191219

1220-
/*! \fn template <typename T> auto qOverload(T functionPointer)
1221-
\relates <QtGlobal>
1222-
\since 5.7
1223-
1224-
Returns a pointer to an overloaded function. The template
1225-
parameter is the list of the argument types of the function.
1226-
\a functionPointer is the pointer to the (member) function:
1227-
1228-
\snippet code/src_corelib_global_qglobal.cpp 52
1229-
1230-
If a member function is also const-overloaded \l qConstOverload and
1231-
\l qNonConstOverload need to be used.
1232-
1233-
qOverload() requires C++14 enabled. In C++11-only code, the helper
1234-
classes QOverload, QConstOverload, and QNonConstOverload can be used directly:
1235-
1236-
\snippet code/src_corelib_global_qglobal.cpp 53
1237-
1238-
\note Qt detects the necessary C++14 compiler support by way of the feature
1239-
test recommendations from
1240-
\l{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations}
1241-
{C++ Committee's Standing Document 6}.
1242-
1243-
\sa qConstOverload(), qNonConstOverload(), {Differences between String-Based
1244-
and Functor-Based Connections}
1245-
*/
1246-
1247-
/*! \fn template <typename T> auto qConstOverload(T memberFunctionPointer)
1248-
\relates <QtGlobal>
1249-
\since 5.7
1250-
1251-
Returns the \a memberFunctionPointer pointer to a constant member function:
1252-
1253-
\snippet code/src_corelib_global_qglobal.cpp 54
1254-
1255-
\sa qOverload, qNonConstOverload, {Differences between String-Based
1256-
and Functor-Based Connections}
1257-
*/
1258-
1259-
/*! \fn template <typename T> auto qNonConstOverload(T memberFunctionPointer)
1260-
\relates <QtGlobal>
1261-
\since 5.7
1262-
1263-
Returns the \a memberFunctionPointer pointer to a non-constant member function:
1264-
1265-
\snippet code/src_corelib_global_qglobal.cpp 54
1266-
1267-
\sa qOverload, qNonConstOverload, {Differences between String-Based
1268-
and Functor-Based Connections}
1269-
*/
1270-
12711220
/*!
12721221
\macro QT_VERSION_CHECK(major, minor, patch)
12731222
\relates <QtGlobal>

src/corelib/global/qglobal.h

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,62 +1213,6 @@ template <typename Ptr> inline auto qGetPtrHelper(Ptr &ptr) noexcept -> decltype
12131213
#define Q_D(Class) Class##Private * const d = d_func()
12141214
#define Q_Q(Class) Class * const q = q_func()
12151215

1216-
#ifdef Q_QDOC
1217-
// Just for documentation generation
1218-
template<typename T>
1219-
auto qOverload(T functionPointer);
1220-
template<typename T>
1221-
auto qConstOverload(T memberFunctionPointer);
1222-
template<typename T>
1223-
auto qNonConstOverload(T memberFunctionPointer);
1224-
#else
1225-
template <typename... Args>
1226-
struct QNonConstOverload
1227-
{
1228-
template <typename R, typename T>
1229-
constexpr auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr)
1230-
{ return ptr; }
1231-
1232-
template <typename R, typename T>
1233-
static constexpr auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr)
1234-
{ return ptr; }
1235-
};
1236-
1237-
template <typename... Args>
1238-
struct QConstOverload
1239-
{
1240-
template <typename R, typename T>
1241-
constexpr auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr)
1242-
{ return ptr; }
1243-
1244-
template <typename R, typename T>
1245-
static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr)
1246-
{ return ptr; }
1247-
};
1248-
1249-
template <typename... Args>
1250-
struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
1251-
{
1252-
using QConstOverload<Args...>::of;
1253-
using QConstOverload<Args...>::operator();
1254-
using QNonConstOverload<Args...>::of;
1255-
using QNonConstOverload<Args...>::operator();
1256-
1257-
template <typename R>
1258-
constexpr auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr)
1259-
{ return ptr; }
1260-
1261-
template <typename R>
1262-
static constexpr auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr)
1263-
{ return ptr; }
1264-
};
1265-
1266-
template <typename... Args> constexpr inline QOverload<Args...> qOverload = {};
1267-
template <typename... Args> constexpr inline QConstOverload<Args...> qConstOverload = {};
1268-
template <typename... Args> constexpr inline QNonConstOverload<Args...> qNonConstOverload = {};
1269-
#endif
1270-
1271-
12721216
class QByteArray;
12731217
Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
12741218
// 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
12901234
"Compile your code with -fPIC (and not with -fPIE)."
12911235
#endif
12921236

1293-
#define QT_VA_ARGS_CHOOSE(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
1294-
#define QT_VA_ARGS_EXPAND(...) __VA_ARGS__ // Needed for MSVC
1295-
#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))
1296-
#define QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC) MACRO##_##ARGC
1297-
#define QT_OVERLOADED_MACRO_IMP(MACRO, ARGC) QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC)
1298-
#define QT_OVERLOADED_MACRO(MACRO, ...) QT_VA_ARGS_EXPAND(QT_OVERLOADED_MACRO_IMP(MACRO, QT_VA_ARGS_COUNT(__VA_ARGS__))(__VA_ARGS__))
1299-
13001237
// This macro can be used to calculate member offsets for types with a non standard layout.
13011238
// It uses the fact that offsetof() is allowed to support those types since C++17 as an optional
13021239
// feature. All our compilers do support this, but some issue a warning, so we wrap the offsetof()
@@ -1322,6 +1259,7 @@ QT_END_NAMESPACE
13221259
#include <QtCore/qforeach.h>
13231260
#include <QtCore/qglobalstatic.h>
13241261
#include <QtCore/qnumeric.h>
1262+
#include <QtCore/qoverload.h>
13251263
#include <QtCore/qtranslation.h>
13261264
#include <QtCore/qversiontagging.h>
13271265

src/corelib/global/qoverload.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 QOVERLOAD_H
5+
#define QOVERLOAD_H
6+
7+
#if 0
8+
#pragma qt_class(QOverload)
9+
#pragma qt_sync_stop_processing
10+
#endif
11+
12+
#ifdef Q_QDOC
13+
// Just for documentation generation
14+
template<typename T>
15+
auto qOverload(T functionPointer);
16+
template<typename T>
17+
auto qConstOverload(T memberFunctionPointer);
18+
template<typename T>
19+
auto qNonConstOverload(T memberFunctionPointer);
20+
#else
21+
template <typename... Args>
22+
struct QNonConstOverload
23+
{
24+
template <typename R, typename T>
25+
constexpr auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr)
26+
{ return ptr; }
27+
28+
template <typename R, typename T>
29+
static constexpr auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr)
30+
{ return ptr; }
31+
};
32+
33+
template <typename... Args>
34+
struct QConstOverload
35+
{
36+
template <typename R, typename T>
37+
constexpr auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr)
38+
{ return ptr; }
39+
40+
template <typename R, typename T>
41+
static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr)
42+
{ return ptr; }
43+
};
44+
45+
template <typename... Args>
46+
struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
47+
{
48+
using QConstOverload<Args...>::of;
49+
using QConstOverload<Args...>::operator();
50+
using QNonConstOverload<Args...>::of;
51+
using QNonConstOverload<Args...>::operator();
52+
53+
template <typename R>
54+
constexpr auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr)
55+
{ return ptr; }
56+
57+
template <typename R>
58+
static constexpr auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr)
59+
{ return ptr; }
60+
};
61+
62+
template <typename... Args> constexpr inline QOverload<Args...> qOverload = {};
63+
template <typename... Args> constexpr inline QConstOverload<Args...> qConstOverload = {};
64+
template <typename... Args> constexpr inline QNonConstOverload<Args...> qNonConstOverload = {};
65+
66+
#endif // Q_QDOC
67+
68+
#define QT_VA_ARGS_CHOOSE(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
69+
#define QT_VA_ARGS_EXPAND(...) __VA_ARGS__ // Needed for MSVC
70+
#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))
71+
#define QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC) MACRO##_##ARGC
72+
#define QT_OVERLOADED_MACRO_IMP(MACRO, ARGC) QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC)
73+
#define QT_OVERLOADED_MACRO(MACRO, ...) QT_VA_ARGS_EXPAND(QT_OVERLOADED_MACRO_IMP(MACRO, QT_VA_ARGS_COUNT(__VA_ARGS__))(__VA_ARGS__))
74+
75+
#endif /* QOVERLOAD_H */

src/corelib/global/qoverload.qdoc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (C) 2022 The Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3+
4+
/*! \fn template <typename T> auto qOverload(T functionPointer)
5+
\relates <QOverload>
6+
\since 5.7
7+
8+
Returns a pointer to an overloaded function. The template
9+
parameter is the list of the argument types of the function.
10+
\a functionPointer is the pointer to the (member) function:
11+
12+
\snippet code/src_corelib_global_qglobal.cpp 52
13+
14+
If a member function is also const-overloaded \l qConstOverload and
15+
\l qNonConstOverload need to be used.
16+
17+
qOverload() requires C++14 enabled. In C++11-only code, the helper
18+
classes QOverload, QConstOverload, and QNonConstOverload can be used directly:
19+
20+
\snippet code/src_corelib_global_qglobal.cpp 53
21+
22+
\note Qt detects the necessary C++14 compiler support by way of the feature
23+
test recommendations from
24+
\l{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations}
25+
{C++ Committee's Standing Document 6}.
26+
27+
\sa qConstOverload(), qNonConstOverload(), {Differences between String-Based
28+
and Functor-Based Connections}
29+
*/
30+
31+
/*! \fn template <typename T> auto qConstOverload(T memberFunctionPointer)
32+
\relates <QOverload>
33+
\since 5.7
34+
35+
Returns the \a memberFunctionPointer pointer to a constant member function:
36+
37+
\snippet code/src_corelib_global_qglobal.cpp 54
38+
39+
\sa qOverload, qNonConstOverload, {Differences between String-Based
40+
and Functor-Based Connections}
41+
*/
42+
43+
/*! \fn template <typename T> auto qNonConstOverload(T memberFunctionPointer)
44+
\relates <QOverload>
45+
\since 5.7
46+
47+
Returns the \a memberFunctionPointer pointer to a non-constant member function:
48+
49+
\snippet code/src_corelib_global_qglobal.cpp 54
50+
51+
\sa qOverload, qNonConstOverload, {Differences between String-Based
52+
and Functor-Based Connections}
53+
*/

0 commit comments

Comments
 (0)