GM2Calc
2.3.0
Loading...
Searching...
No Matches
src
gm2_raii.hpp
Go to the documentation of this file.
1
// ====================================================================
2
// This file is part of GM2Calc.
3
//
4
// GM2Calc is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published
6
// by the Free Software Foundation, either version 3 of the License,
7
// or (at your option) any later version.
8
//
9
// GM2Calc is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with GM2Calc. If not, see
16
// <http://www.gnu.org/licenses/>.
17
// ====================================================================
18
19
#ifndef GM2_RAII_HPP
20
#define GM2_RAII_HPP
21
22
namespace
gm2calc
{
23
24
/**
25
* @class RAII_save
26
* @brief Saves value of variable and restores it at destruction
27
*/
28
template
<
typename
T>
29
class
RAII_save
{
30
public
:
31
explicit
RAII_save
(
T
&
var_
)
noexcept
: var(
var_
), value(
var_
) {}
32
RAII_save
(
const
RAII_save
&) =
delete
;
33
RAII_save
(
RAII_save
&&)
noexcept
=
default
;
34
~
RAII_save
() { var = value; }
35
RAII_save
&
operator=
(
const
RAII_save
&) =
delete
;
36
RAII_save
&
operator=
(
RAII_save
&&
other
)
noexcept
=
default
;
37
38
private
:
39
T
& var;
40
T
value{};
41
};
42
43
template
<
typename
T>
44
constexpr
RAII_save<T>
make_raii_save
(
T
& var)
45
{
46
return
RAII_save<T>
(var);
47
}
48
49
}
// namespace gm2calc
50
51
#endif
gm2calc::RAII_save
Saves value of variable and restores it at destruction.
Definition
gm2_raii.hpp:29
gm2calc::RAII_save::operator=
RAII_save & operator=(const RAII_save &)=delete
gm2calc::RAII_save::RAII_save
RAII_save(T &var_) noexcept
Definition
gm2_raii.hpp:31
gm2calc::RAII_save::RAII_save
RAII_save(RAII_save &&) noexcept=default
gm2calc::RAII_save::RAII_save
RAII_save(const RAII_save &)=delete
gm2calc::RAII_save::operator=
RAII_save & operator=(RAII_save &&other) noexcept=default
gm2calc
Definition
gm2_config_options.hpp:22
gm2calc::svd_eigen
void svd_eigen(const Eigen::Matrix< Scalar, M, N > &m, Eigen::Array< Real,(((M)<(N)) ?(M) :(N)), 1 > &s, Eigen::Matrix< Scalar, M, M > *u, Eigen::Matrix< Scalar, N, N > *vh)
Definition
gm2_linalg.hpp:40
gm2calc::make_raii_save
constexpr RAII_save< T > make_raii_save(T &var)
Definition
gm2_raii.hpp:44
Generated by
1.9.8