Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:33

0001 // Copyright (C) 2022 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QOVERLOAD_H
0005 #define QOVERLOAD_H
0006 
0007 #include <QtCore/qtconfigmacros.h>
0008 
0009 #if 0
0010 #pragma qt_class(QOverload)
0011 #endif
0012 
0013 QT_BEGIN_NAMESPACE
0014 
0015 #ifdef Q_QDOC
0016 // Just for documentation generation
0017 template<typename T>
0018 auto qOverload(T functionPointer);
0019 template<typename T>
0020 auto qConstOverload(T memberFunctionPointer);
0021 template<typename T>
0022 auto qNonConstOverload(T memberFunctionPointer);
0023 #else
0024 template <typename... Args>
0025 struct QNonConstOverload
0026 {
0027     template <typename R, typename T>
0028     constexpr auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr)
0029     { return ptr; }
0030 
0031     template <typename R, typename T>
0032     static constexpr auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr)
0033     { return ptr; }
0034 };
0035 
0036 template <typename... Args>
0037 struct QConstOverload
0038 {
0039     template <typename R, typename T>
0040     constexpr auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr)
0041     { return ptr; }
0042 
0043     template <typename R, typename T>
0044     static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr)
0045     { return ptr; }
0046 };
0047 
0048 template <typename... Args>
0049 struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
0050 {
0051     using QConstOverload<Args...>::of;
0052     using QConstOverload<Args...>::operator();
0053     using QNonConstOverload<Args...>::of;
0054     using QNonConstOverload<Args...>::operator();
0055 
0056     template <typename R>
0057     constexpr auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr)
0058     { return ptr; }
0059 
0060     template <typename R>
0061     static constexpr auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr)
0062     { return ptr; }
0063 };
0064 
0065 template <typename... Args> constexpr inline QOverload<Args...> qOverload = {};
0066 template <typename... Args> constexpr inline QConstOverload<Args...> qConstOverload = {};
0067 template <typename... Args> constexpr inline QNonConstOverload<Args...> qNonConstOverload = {};
0068 
0069 #endif // Q_QDOC
0070 
0071 #define QT_VA_ARGS_CHOOSE(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
0072 #define QT_VA_ARGS_EXPAND(...) __VA_ARGS__ // Needed for MSVC
0073 #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))
0074 #define QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC) MACRO##_##ARGC
0075 #define QT_OVERLOADED_MACRO_IMP(MACRO, ARGC) QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC)
0076 #define QT_OVERLOADED_MACRO(MACRO, ...) QT_VA_ARGS_EXPAND(QT_OVERLOADED_MACRO_IMP(MACRO, QT_VA_ARGS_COUNT(__VA_ARGS__))(__VA_ARGS__))
0077 
0078 QT_END_NAMESPACE
0079 
0080 #endif /* QOVERLOAD_H */