File indexing completed on 2025-01-18 10:07:35
0001
0002
0003
0004 #ifndef QSCOPEDVALUEROLLBACK_H
0005 #define QSCOPEDVALUEROLLBACK_H
0006
0007 #include <QtCore/qglobal.h>
0008
0009 QT_BEGIN_NAMESPACE
0010
0011 template <typename T>
0012 class QScopedValueRollback
0013 {
0014 public:
0015 Q_NODISCARD_CTOR
0016 explicit constexpr QScopedValueRollback(T &var)
0017 : varRef(var), oldValue(var)
0018 {
0019 }
0020
0021 Q_NODISCARD_CTOR
0022 explicit constexpr QScopedValueRollback(T &var, T value)
0023 : varRef(var), oldValue(std::move(var))
0024 {
0025 var = std::move(value);
0026 }
0027
0028 #if __cpp_constexpr >= 201907L
0029 constexpr
0030 #endif
0031 ~QScopedValueRollback()
0032 {
0033 varRef = std::move(oldValue);
0034 }
0035
0036 constexpr void commit()
0037 {
0038 oldValue = varRef;
0039 }
0040
0041 private:
0042 T &varRef;
0043 T oldValue;
0044
0045 Q_DISABLE_COPY_MOVE(QScopedValueRollback)
0046 };
0047
0048 QT_END_NAMESPACE
0049
0050 #endif