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
qscopedvaluerollback.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QSCOPEDVALUEROLLBACK_H
5#define QSCOPEDVALUEROLLBACK_H
6
7#include <QtCore/qglobal.h>
8
10
11template <typename T>
13{
14public:
16 explicit constexpr QScopedValueRollback(T &var)
17 : varRef(var), oldValue(var)
18 {
19 }
20
22 explicit constexpr QScopedValueRollback(T &var, T value)
23 : varRef(var), oldValue(std::move(var)) // ### C++20: std::exchange(var, std::move(value))
24 {
25 var = std::move(value);
26 }
27
28#if __cpp_constexpr >= 201907L
29 constexpr
30#endif
32 {
33 varRef = std::move(oldValue);
34 }
35
36 constexpr void commit()
37 {
38 oldValue = varRef;
39 }
40
41private:
42 T &varRef;
43 T oldValue;
44
45 Q_DISABLE_COPY_MOVE(QScopedValueRollback)
46};
47
49
50#endif // QSCOPEDVALUEROLLBACK_H
constexpr void commit()
Updates the previous value of the managed variable to its current value.
~QScopedValueRollback()
Assigns the previous value to the managed variable.
Q_NODISCARD_CTOR constexpr QScopedValueRollback(T &var, T value)
Assigns value to \ var and stores the previous value of var internally, for revert on destruction.
Q_NODISCARD_CTOR constexpr QScopedValueRollback(T &var)
Stores the previous value of var internally, for revert on destruction.
Combined button and popup list for selecting options.
#define Q_NODISCARD_CTOR
EGLOutputLayerEXT EGLint EGLAttrib value
[5]