Himalaya
RAII.hpp
Go to the documentation of this file.
1 // ====================================================================
2 // This file is part of Himalaya.
3 //
4 // Himalaya is licenced under the GNU General Public License (GNU GPL)
5 // version 3.
6 // ====================================================================
7 
8 #pragma once
9 
10 namespace himalaya {
11 
12 /// temporarily sets a variable to a new value, and resets the value
13 /// to the old one when destoyed
14 template <class T>
16 public:
17  Temporarily_set(T& variable_, T new_value_) noexcept
18  : variable(variable_)
19  , old_value(variable_)
20  {
21  variable_ = new_value_;
22  }
23  Temporarily_set(const Temporarily_set&) = delete;
24  Temporarily_set(Temporarily_set&&) noexcept = delete;
26  Temporarily_set& operator=(const Temporarily_set&) = delete;
27  Temporarily_set& operator=(Temporarily_set&& other) noexcept = delete;
28 private:
31 };
32 
33 } // namespace himalaya
Definition: H3.cpp:14
Temporarily_set & operator=(const Temporarily_set &)=delete
Temporarily_set(T &variable_, T new_value_) noexcept
Definition: RAII.hpp:17