Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
q20type_traits.h
Go to the documentation of this file.
1// Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef Q20TYPE_TRAITS_H
4#define Q20TYPE_TRAITS_H
5
6#include <QtCore/qcompilerdetection.h>
7#include <QtCore/qsystemdetection.h>
8#include <QtCore/qtconfigmacros.h>
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. Types and functions defined in this
15// file can reliably be replaced by their std counterparts, once available.
16// You may use these definitions in your own code, but be aware that we
17// will remove them once Qt depends on the C++ version that supports
18// them in namespace std. There will be NO deprecation warning, the
19// definitions will JUST go away.
20//
21// If you can't agree to these terms, don't use these definitions!
22//
23// We mean it.
24//
25
26#include <type_traits>
27
29
30namespace q20 {
31// like std::is_constant_evaluated
32#ifdef __cpp_lib_is_constant_evaluated
33using std::is_constant_evaluated;
34#define QT_SUPPORTS_IS_CONSTANT_EVALUATED
35#else
36constexpr bool is_constant_evaluated() noexcept
37{
38#ifdef Q_OS_INTEGRITY
39 // Integrity complains "calling __has_builtin() from a constant expression".
40 // Avoid the __has_builtin check until we know what's going on.
41 return false;
42#elif __has_builtin(__builtin_is_constant_evaluated) || \
43 (defined(Q_CC_MSVC_ONLY) /* >= 1925, but we require 1927 in qglobal.h */)
44# define QT_SUPPORTS_IS_CONSTANT_EVALUATED
45 return __builtin_is_constant_evaluated();
46#else
47 return false;
48#endif
49}
50#endif // __cpp_lib_is_constant_evaluated
51}
52
53namespace q20 {
54// like std::remove_cvref(_t)
55#ifdef __cpp_lib_remove_cvref
56using std::remove_cvref;
57using std::remove_cvref_t;
58#else
59template <typename T>
60using remove_cvref = std::remove_cv<std::remove_reference_t<T>>;
61template <typename T>
62using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
63#endif // __cpp_lib_remove_cvref
64}
65
66namespace q20 {
67// like std::type_identity(_t)
68#ifdef __cpp_lib_type_identity
69using std::type_identity;
70using std::type_identity_t;
71#else
72template <typename T>
73struct type_identity { using type = T; };
74template <typename T>
76#endif // __cpp_lib_type_identity
77}
78
80
81#endif /* Q20TYPE_TRAITS_H */
Combined button and popup list for selecting options.
constexpr bool is_constant_evaluated() noexcept
std::remove_cv_t< std::remove_reference_t< T > > remove_cvref_t
typename type_identity< T >::type type_identity_t
std::remove_cv< std::remove_reference_t< T > > remove_cvref