Himalaya
source
himalaya
misc
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>
15
class
Temporarily_set
{
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
;
25
~Temporarily_set
() {
variable
=
old_value
; }
26
Temporarily_set
&
operator=
(
const
Temporarily_set
&) =
delete
;
27
Temporarily_set
&
operator=
(
Temporarily_set
&& other) noexcept =
delete
;
28
private
:
29
T&
variable
;
30
T
old_value
;
31
};
32
33
}
// namespace himalaya
himalaya
Definition:
H3.cpp:14
himalaya::Temporarily_set::operator=
Temporarily_set & operator=(const Temporarily_set &)=delete
himalaya::Temporarily_set::variable
T & variable
Definition:
RAII.hpp:29
himalaya::Temporarily_set::~Temporarily_set
~Temporarily_set()
Definition:
RAII.hpp:25
himalaya::Temporarily_set::old_value
T old_value
Definition:
RAII.hpp:30
himalaya::Temporarily_set::Temporarily_set
Temporarily_set(T &variable_, T new_value_) noexcept
Definition:
RAII.hpp:17
himalaya::Temporarily_set
Definition:
RAII.hpp:15
Generated by
1.8.13