libdl
0.0.1
Simple yet powerful deep learning
Loading...
Searching...
No Matches
scopeguard.hpp
1
#pragma once
2
3
#include <assert.h>
4
#include <functional>
5
6
namespace
dl::utils {
16
class
ScopeGuard
final {
17
private
:
18
std::function
<void()> onScopeExit;
19
20
ScopeGuard
(
const
ScopeGuard
&) =
delete
;
21
ScopeGuard
& operator=(
const
ScopeGuard
&) =
delete
;
22
23
public
:
24
explicit
ScopeGuard
(
auto
&& onScopeExit)
try
: onScopeExit(
std::forward
<
decltype
(onScopeExit)>(onScopeExit)) {
25
}
catch
(...) {
26
onScopeExit();
27
throw
;
28
}
29
30
explicit
ScopeGuard
(
ScopeGuard
&& other) : onScopeExit(
std::move
(other.onScopeExit)) {
31
assert(other.onScopeExit ==
nullptr
);
32
}
33
34
~ScopeGuard
() {
35
if
(onScopeExit !=
nullptr
)
36
onScopeExit();
37
}
38
};
39
}
// namespace dl::utils
dl::utils::ScopeGuard
Definition
scopeguard.hpp:16
std::forward
T forward(T... args)
std::function
std::move
T move(T... args)
dl
utils
scopeguard.hpp
Generated by
1.9.8