ttg
1.0.0
Template Task Graph (TTG): flowgraph-based programming model for high-performance distributed-memory algorithms
Loading...
Searching...
No Matches
ttg
ttg
util
scope_exit.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSD-3-Clause
2
#ifndef TTG_UTIL_SCOPE_EXIT_H
3
#define TTG_UTIL_SCOPE_EXIT_H
4
5
//
6
// N4189: Scoped Resource - Generic RAII Wrapper for the Standard Library
7
// Peter Sommerlad and Andrew L. Sandoval
8
// Adopted from https://github.com/tandasat/ScopedResource/tree/master
9
//
10
11
#include <type_traits>
12
13
namespace
ttg::detail
{
14
template
<
typename
EF>
15
struct
scope_exit
16
{
17
// construction
18
explicit
19
scope_exit
(EF &&f)
20
: exit_function(
std
::move(f))
21
, execute_on_destruction{ true }
22
{ }
23
24
// move
25
scope_exit
(
scope_exit
&&rhs)
26
: exit_function(
std
::move(rhs.exit_function))
27
, execute_on_destruction{ rhs.execute_on_destruction }
28
{
29
rhs.release();
30
}
31
32
// release
33
~scope_exit
()
34
{
35
if
(execute_on_destruction) this->exit_function();
36
}
37
38
void
release
()
39
{
40
this->execute_on_destruction =
false
;
41
}
42
43
private
:
44
scope_exit
(
scope_exit
const
&) =
delete
;
45
void
operator=(
scope_exit
const
&) =
delete
;
46
scope_exit
& operator=(
scope_exit
&&) =
delete
;
47
EF exit_function;
48
bool
execute_on_destruction;
// exposition only
49
};
50
51
template
<
typename
EF>
52
auto
make_scope_exit
(EF &&exit_function)
53
{
54
return
scope_exit<std::remove_reference_t<EF>
>(std::forward<EF>(exit_function));
55
}
56
57
}
// namespace ttg::detail
58
59
#endif
// TTG_UTIL_SCOPE_EXIT_H
std
STL namespace.
ttg::detail
Definition
keymap.h:10
ttg::detail::make_scope_exit
auto make_scope_exit(EF &&exit_function)
Definition
scope_exit.h:52
ttg::detail::scope_exit
Definition
scope_exit.h:16
ttg::detail::scope_exit::scope_exit
scope_exit(scope_exit &&rhs)
Definition
scope_exit.h:25
ttg::detail::scope_exit::scope_exit
scope_exit(EF &&f)
Definition
scope_exit.h:19
ttg::detail::scope_exit::release
void release()
Definition
scope_exit.h:38
ttg::detail::scope_exit::~scope_exit
~scope_exit()
Definition
scope_exit.h:33
Generated at Mon Nov 24 2025 13:41:21 for
ttg
1.0.0 by
1.9.8