1 | // Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> |
2 | // Copyright (C) 2022 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
4 | |
5 | #ifndef QXPTYPE_TRAITS_H |
6 | #define QXPTYPE_TRAITS_H |
7 | |
8 | #include <QtCore/qtconfigmacros.h> |
9 | |
10 | #include <type_traits> |
11 | |
12 | // |
13 | // W A R N I N G |
14 | // ------------- |
15 | // |
16 | // This file is not part of the Qt API. Types and functions defined in this |
17 | // file can reliably be replaced by their std counterparts, once available. |
18 | // You may use these definitions in your own code, but be aware that we |
19 | // will remove them once Qt depends on the C++ version that supports |
20 | // them in namespace std. There will be NO deprecation warning, the |
21 | // definitions will JUST go away. |
22 | // |
23 | // If you can't agree to these terms, don't use these definitions! |
24 | // |
25 | // We mean it. |
26 | // |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | // like std::experimental::{nonesuch,is_detected/_v}(LFTSv2) |
31 | namespace qxp { |
32 | |
33 | struct nonesuch { |
34 | ~nonesuch() = delete; |
35 | nonesuch(const nonesuch&) = delete; |
36 | void operator=(const nonesuch&) = delete; |
37 | }; |
38 | |
39 | namespace _detail { |
40 | template <typename T, typename Void, template <typename...> class Op, typename...Args> |
41 | struct detector { |
42 | using value_t = std::false_type; |
43 | using type = T; |
44 | }; |
45 | template <typename T, template <typename...> class Op, typename...Args> |
46 | struct detector<T, std::void_t<Op<Args...>>, Op, Args...> { |
47 | using value_t = std::true_type; |
48 | using type = Op<Args...>; |
49 | }; |
50 | } // namespace _detail |
51 | |
52 | template <template <typename...> class Op, typename...Args> |
53 | using is_detected = typename _detail::detector<qxp::nonesuch, void, Op, Args...>::value_t; |
54 | |
55 | template <template <typename...> class Op, typename...Args> |
56 | constexpr inline bool is_detected_v = is_detected<Op, Args...>::value; |
57 | |
58 | } // namespace qxp |
59 | |
60 | QT_END_NAMESPACE |
61 | |
62 | #endif // QXPTYPE_TRAITS_H |
63 | |
64 | |