Sen API
Sen Libraries
Toggle main menu visibility
Loading...
Searching...
No Matches
scope_guard.h
Go to the documentation of this file.
1
// === scope_guard.h ===================================================================================================
2
// Sen Infrastructure
3
// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4
// See the LICENSE.txt file for more information.
5
// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6
// =====================================================================================================================
7
8
#ifndef SEN_CORE_BASE_SCOPE_GUARD_H
9
#define SEN_CORE_BASE_SCOPE_GUARD_H
10
11
#include "
sen/core/base/class_helpers.h
"
12
13
namespace
sen
14
{
15
18
20
template
<
class
F>
21
[[nodiscard]]
auto
makeScopeGuard
(F&& f);
22
24
template
<
typename
F>
25
class
[[nodiscard]]
ScopeGuard
26
{
27
SEN_NOCOPY_NOMOVE(
ScopeGuard
)
28
29
public
:
// special members
30
ScopeGuard
() =
delete
;
31
32
public
:
34
~ScopeGuard
() noexcept { f_(); }
35
36
private
:
37
explicit
ScopeGuard
(F&& f): f_(
std
::move(f)) {}
38
39
template
<
class
InputF>
40
friend
auto
makeScopeGuard(InputF&& f);
41
42
private
:
43
F f_;
44
};
45
46
template
<
class
F>
47
ScopeGuard
(F) ->
ScopeGuard<F>
;
48
49
// Deleted overloads for making scope guards.
50
// The function must be called on a rvalue reference
51
52
template
<
class
F>
53
auto
makeScopeGuard
(
const
F&& f) =
delete
;
54
55
template
<
class
F>
56
auto
makeScopeGuard
(F& f) =
delete
;
57
58
template
<
class
F>
59
auto
makeScopeGuard
(
const
F& f) =
delete
;
60
62
63
template
<
typename
InputF>
64
auto
makeScopeGuard
(InputF&& f)
65
{
66
return
ScopeGuard
{std::forward<InputF>(f)};
67
}
68
69
}
// namespace sen
70
71
#endif
// SEN_CORE_BASE_SCOPE_GUARD_H
class_helpers.h
Here we define a set of template meta-programming helpers to let the compiler take some decisions bas...
sen::ScopeGuard
Runs the function object F on destruction.
Definition
scope_guard.h:26
sen::ScopeGuard::ScopeGuard
ScopeGuard()=delete
sen::ScopeGuard::~ScopeGuard
~ScopeGuard() noexcept
Will trigger the given callback.
Definition
scope_guard.h:34
sen::makeScopeGuard
auto makeScopeGuard(F &&f)
Makes scope guard from a callable taking no arguments.
sen::ScopeGuard
ScopeGuard(F) -> ScopeGuard< F >
sen
Definition
assert.h:17
std
STL namespace.
libs
core
include
sen
core
base
scope_guard.h
Generated by
1.17.0