| 1 | // Copyright (C) 2021 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 QQMLDOMFUNCTIONREF_P_H |
| 5 | #define QQMLDOMFUNCTIONREF_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/private/qglobal_p.h> |
| 19 | |
| 20 | #if !defined(Q_CC_MSVC) || Q_CC_MSVC >= 1930 |
| 21 | #include <QtCore/qxpfunctional.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | namespace QQmlJS { |
| 25 | namespace Dom { |
| 26 | template <typename T> |
| 27 | using function_ref = qxp::function_ref<T>; |
| 28 | } // namespace Dom |
| 29 | } // namespace QQmlJS |
| 30 | QT_END_NAMESPACE |
| 31 | |
| 32 | #else |
| 33 | |
| 34 | #include <functional> |
| 35 | |
| 36 | QT_BEGIN_NAMESPACE |
| 37 | namespace QQmlJS { |
| 38 | namespace Dom { |
| 39 | namespace _detail { |
| 40 | template <typename T> |
| 41 | struct function_ref_helper { using type = std::function<T>; }; |
| 42 | // std::function doesn't grok the const in <int(int) const>, so remove: |
| 43 | template <typename R, typename...Args> |
| 44 | struct function_ref_helper<R(Args...) const> : function_ref_helper<R(Args...)> {}; |
| 45 | // std::function doesn't grok the noexcept in <int(int) noexcept>, so remove: |
| 46 | template <typename R, typename...Args> |
| 47 | struct function_ref_helper<R(Args...) noexcept> : function_ref_helper<R(Args...)> {}; |
| 48 | // and both together: |
| 49 | template <typename R, typename...Args> |
| 50 | struct function_ref_helper<R(Args...) const noexcept> : function_ref_helper<R(Args...)> {}; |
| 51 | } // namespace _detail |
| 52 | template <typename T> |
| 53 | using function_ref = const typename _detail::function_ref_helper<T>::type &; |
| 54 | } // namespace Dom |
| 55 | } // namespace QQmlJS |
| 56 | QT_END_NAMESPACE |
| 57 | |
| 58 | #endif |
| 59 | |
| 60 | #endif // QQMLDOMFUNCTIONREF_P_H |
| 61 | |