legate::ScopeGuard#
-
template<typename F>
class ScopeGuard# A simple wrapper around a callable that automatically executes the callable on exiting the scope.
- Template Parameters:
F – The type of the callable to execute.
Public Types
-
using value_type = F#
The type of callable stored within the ScopeGuard.
Public Functions
-
explicit ScopeGuard(value_type &&fn, bool enabled = true) noexcept#
Construct a ScopeGuard.
On destruction, a ScopeGuard will execute
fn
if and only if it is in the enabled state.fn
will be invoked with no arguments, and any return value discarded.fn
must be no-throw move-constructible, and must not throw any exceptions when invoked.See also
See also
See also
See also
- Parameters:
fn – The function to execute.
enabled – Whether the ScopeGuard should start in the “enabled” state.
-
ScopeGuard(ScopeGuard &&other) noexcept#
Move-construct a ScopeGuard.
other
will be left in the “disabled” state, and will not execute its held functor upon destruction. Furthermore, the held functor is moved into the receiving ScopeGuard, soother's
functor may be in an indeterminate state. It is therefore not advised to re-enableother
.- Parameters:
other – The ScopeGuard to move from.
-
ScopeGuard &operator=(ScopeGuard &&other) noexcept#
Construct a ScopeGuard via move-assignment.
This routine has no effect if
other
andthis
are the same.other
will be left in the “disabled” state, and will not execute its held functor upon destruction. Furthermore, the held functor is moved into the receiving ScopeGuard, soother's
functor may be in an indeterminate state. It is therefore not advised to re-enableother
.- Parameters:
other – The ScopeGuard to move from.
- Returns:
A reference to
this
.
-
~ScopeGuard() noexcept#
Destroy a ScopeGuard.
If the ScopeGuard is currently in the enabled state, executes the held functor, otherwise does nothing.
-
bool enabled() const#
Query a ScopeGuard’s state.
See also
See also
- Returns:
true if the ScopeGuard is enabled, false otherwise.
-
void disable()#
Disable a ScopeGuard.
This routine prevents a ScopeGuard from executing its held functor on destruction. On return, ScopeGuard::enabled() will return false.
Calling this routine on an already disabled ScopeGuard has no effect.
See also
-
void enable()#
Enable a ScopeGuard.
This routine makes a ScopeGuard execute its held functor on destruction. On return, ScopeGuard::enabled() will return true.
Calling this routine on an already enabled ScopeGuard has no effect.
See also