Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QSCOPEDVALUEROLLBACK_H
6#define QSCOPEDVALUEROLLBACK_H
7
8#include <QtCore/qglobal.h>
9
10#include <QtCore/q20utility.h>
11
13
14template <typename T>
15class QScopedValueRollback
16{
17public:
18 Q_NODISCARD_CTOR
19 explicit constexpr QScopedValueRollback(T &var)
20 : varRef(var), oldValue(var)
21 {
22 }
23
24 Q_NODISCARD_CTOR
25 explicit constexpr QScopedValueRollback(T &var, T value)
26 : varRef(var), oldValue(q20::exchange(var, std::move(value)))
27 {
28 }
29
30 Q_DECL_CONSTEXPR_DTOR
31 ~QScopedValueRollback()
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
48QT_END_NAMESPACE
49
50#endif // QSCOPEDVALUEROLLBACK_H
void insert(const QProcessEnvironmentPrivate &other)
Definition qprocess.cpp:100
QStringList keys() const
Definition qprocess.cpp:89
\inmodule QtCore
Definition qprocess.h:33
Combined button and popup list for selecting options.
#define __has_include(x)
bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs)