1 | // Copyright (C) 2024 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 Q20UTILITY_H |
5 | #define Q20UTILITY_H |
6 | |
7 | #include <QtCore/qtconfigmacros.h> |
8 | |
9 | #include <utility> |
10 | |
11 | // |
12 | // W A R N I N G |
13 | // ------------- |
14 | // |
15 | // This file is not part of the Qt API. Types and functions defined in this |
16 | // file can reliably be replaced by their std counterparts, once available. |
17 | // You may use these definitions in your own code, but be aware that we |
18 | // will remove them once Qt depends on the C++ version that supports |
19 | // them in namespace std. There will be NO deprecation warning, the |
20 | // definitions will JUST go away. |
21 | // |
22 | // If you can't agree to these terms, don't use these definitions! |
23 | // |
24 | // We mean it. |
25 | // |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | // like C++20 std::exchange (ie. constexpr, not yet noexcept) |
30 | namespace q20 { |
31 | #ifdef __cpp_lib_constexpr_algorithms |
32 | using std::exchange; |
33 | #else |
34 | template <typename T, typename U = T> |
35 | constexpr T exchange(T& obj, U&& newValue) |
36 | { |
37 | T old = std::move(obj); |
38 | obj = std::forward<U>(newValue); |
39 | return old; |
40 | } |
41 | #endif |
42 | } |
43 | |
44 | QT_END_NAMESPACE |
45 | |
46 | #endif /* Q20UTILITY_H */ |
47 |
Definitions
Learn Advanced QML with KDAB
Find out more