| 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 | #ifndef Q23FUNCTIONAL_H |
| 4 | #define Q23FUNCTIONAL_H |
| 5 | |
| 6 | #include <QtCore/qglobal.h> |
| 7 | #include <QtCore/q20functional.h> |
| 8 | |
| 9 | // |
| 10 | // W A R N I N G |
| 11 | // ------------- |
| 12 | // |
| 13 | // This file is not part of the Qt API. Types and functions defined in this |
| 14 | // file can reliably be replaced by their std counterparts, once available. |
| 15 | // You may use these definitions in your own code, but be aware that we |
| 16 | // will remove them once Qt depends on the C++ version that supports |
| 17 | // them in namespace std. There will be NO deprecation warning, the |
| 18 | // definitions will JUST go away. |
| 19 | // |
| 20 | // If you can't agree to these terms, don't use these definitions! |
| 21 | // |
| 22 | // We mean it. |
| 23 | // |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | namespace q23 { |
| 28 | // like std::invoke_r |
| 29 | #ifdef __cpp_lib_invoke_r |
| 30 | using std::invoke_r; |
| 31 | #else |
| 32 | template <typename R, typename F, typename...Args> |
| 33 | constexpr |
| 34 | std::enable_if_t<std::is_invocable_r_v<R, F, Args...>, R> |
| 35 | invoke_r(F&& f, Args&&... args) |
| 36 | noexcept(std::is_nothrow_invocable_r_v<R, F, Args...>) |
| 37 | { |
| 38 | // ### use q20::invoke for a constexpr std::invoke |
| 39 | if constexpr (std::is_void_v<R>) |
| 40 | std::invoke(std::forward<F>(f), std::forward<Args>(args)...); |
| 41 | else |
| 42 | return std::invoke(std::forward<F>(f), std::forward<Args>(args)...); |
| 43 | } |
| 44 | #endif // __cpp_lib_invoke_r |
| 45 | } // namespace q23 |
| 46 | |
| 47 | QT_END_NAMESPACE |
| 48 | |
| 49 | #endif /* Q23FUNCTIONAL_H */ |
| 50 | |