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
4#ifndef QSCOPEDVALUEROLLBACK_H
5#define QSCOPEDVALUEROLLBACK_H
6
7#include <QtCore/qglobal.h>
8
9#include <QtCore/q20utility.h>
10
12
13template <typename T>
14class QScopedValueRollback
15{
16public:
17 Q_NODISCARD_CTOR
18 explicit constexpr QScopedValueRollback(T &var)
19 : varRef(var), oldValue(var)
20 {
21 }
22
23 Q_NODISCARD_CTOR
24 explicit constexpr QScopedValueRollback(T &var, T value)
25 : varRef(var), oldValue(q20::exchange(var, std::move(value)))
26 {
27 }
28
29 Q_DECL_CONSTEXPR_DTOR
30 ~QScopedValueRollback()
31 {
32 varRef = std::move(oldValue);
33 }
34
35 constexpr void commit()
36 {
37 oldValue = varRef;
38 }
39
40private:
41 T &varRef;
42 T oldValue;
43
44 Q_DISABLE_COPY_MOVE(QScopedValueRollback)
45};
46
47QT_END_NAMESPACE
48
49#endif // QSCOPEDVALUEROLLBACK_H
void insert(const QProcessEnvironmentPrivate &other)
Definition qprocess.cpp:99
QStringList keys() const
Definition qprocess.cpp:88
\inmodule QtCore
Definition qprocess.h:32
Combined button and popup list for selecting options.
#define __has_include(x)
bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs)