Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:35

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
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)) // ### C++20: std::exchange(var, std::move(value))
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 // QSCOPEDVALUEROLLBACK_H