FTXUI  0.11.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
autoreset.hpp
Go to the documentation of this file.
1#ifndef FTXUI_UTIL_AUTORESET_HPP
2#define FTXUI_UTIL_AUTORESET_HPP
3
4#include <utility>
5
6namespace ftxui {
7
8/// Assign a value to a variable, reset its old value when going out of scope.
9template <typename T>
10class AutoReset {
11 public:
12 AutoReset(T* variable, T new_value)
13 : variable_(variable), previous_value_(std::move(*variable)) {
14 *variable_ = std::move(new_value);
15 }
16 ~AutoReset() { *variable_ = std::move(previous_value_); }
17
18 private:
19 T* variable_;
20 T previous_value_;
21};
22
23} // namespace ftxui
24
25#endif /* end of include guard: FTXUI_UTIL_AUTORESET_HPP */
26
27// Copyright 2020 Arthur Sonzogni. All rights reserved.
28// Use of this source code is governed by the MIT license that can be found in
29// the LICENSE file.
Assign a value to a variable, reset its old value when going out of scope.
Definition autoreset.hpp:10
AutoReset(T *variable, T new_value)
Definition autoreset.hpp:12