Loading...
Searching...
No Matches
autoreset.hpp
Go to the documentation of this file.
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#ifndef FTXUI_UTIL_AUTORESET_HPP
#define FTXUI_UTIL_AUTORESET_HPP
#include <utility>
namespace ftxui {
/// Assign a value to a variable, reset its old value when going out of scope.
template <typename T>
class AutoReset {
public:
AutoReset(T* variable, T new_value)
: variable_(variable), previous_value_(std::move(*variable)) {
*variable_ = std::move(new_value);
}
AutoReset(const AutoReset&) = delete;
AutoReset(AutoReset&&) = delete;
AutoReset& operator=(const AutoReset&) = delete;
AutoReset& operator=(AutoReset&&) = delete;
~AutoReset() { *variable_ = std::move(previous_value_); }
private:
T* variable_;
T previous_value_;
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_UTIL_AUTORESET_HPP */
ftxui::AutoReset
Assign a value to a variable, reset its old value when going out of scope.
Definition autoreset.hpp:13
ftxui::AutoReset::AutoReset
AutoReset(const AutoReset &)=delete
ftxui::AutoReset::operator=
AutoReset & operator=(AutoReset &&)=delete
ftxui::AutoReset::operator=
AutoReset & operator=(const AutoReset &)=delete
ftxui::AutoReset::AutoReset
AutoReset(AutoReset &&)=delete
ftxui::AutoReset::~AutoReset
~AutoReset()
Definition autoreset.hpp:23
ftxui::AutoReset::AutoReset
AutoReset(T *variable, T new_value)
Definition autoreset.hpp:15
ftxui
Definition animation.hpp:10
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26