5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_SCOPE_GUARD_SCOPE_GUARD_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_SCOPE_GUARD_SCOPE_GUARD_HPP_
14#include "arene/base/stdlib_choice/enable_if.hpp"
15#include "arene/base/stdlib_choice/exchange.hpp"
16#include "arene/base/stdlib_choice/forward.hpp"
17#include "arene/base/stdlib_choice/is_constructible.hpp"
18#include "arene/base/stdlib_choice/is_move_constructible.hpp"
19#include "arene/base/stdlib_choice/is_same.hpp"
20#include "arene/base/stdlib_choice/move.hpp"
21#include "arene/base/stdlib_choice/remove_cv.hpp"
22#include "arene/base/stdlib_choice/remove_reference.hpp"
42template <
typename Func>
60 : func_(
std::forward<Func2>(supplied_callable)),
92 void cancel() noexcept { cancelled_ =
true; }
121template <
typename CallableType, constra
ints<std::enable_if_t<is_nothrow_invocable_r_v<
void, CallableType>>> =
nullptr>
RAII utility for executing logic on scope exit.
Definition scope_guard.hpp:43
auto operator=(scope_guard const &) -> scope_guard &=delete
copy-assignment is deleted as two guards cannot own the same function.
void cancel() noexcept
Declares the held function should not be invoked.
Definition scope_guard.hpp:92
auto operator=(scope_guard &&other) -> scope_guard &=delete
Move assignment is deleted as allowing it would overwrite the existing guard function without executi...
scope_guard(scope_guard &&other) noexcept
Move constructor.
Definition scope_guard.hpp:72
scope_guard(Func2 &&supplied_callable) noexcept(std::is_nothrow_constructible< Func, Func2 >::value)
Construct a new scope_guard that decay-copies the function and ensure that it is called upon destruct...
Definition scope_guard.hpp:59
~scope_guard()
Destroy the scope guard and invoke the function if it should be executed.
Definition scope_guard.hpp:88
void invoke_now() noexcept
Invokes the held function if it has not be otherwise canceled.
Definition scope_guard.hpp:97
scope_guard(scope_guard const &)=delete
copy-construction is deleted as two guards cannot own the same function.
static constexpr value_type value
Definition integral_constant.hpp:34
Type trait to detect if a type is constructible from arguments of the specified types and is noexcept...
Definition is_constructible.hpp:84
Definition accumulate.hpp:37
constexpr bool is_nothrow_invocable_r_v
Determine if a functor type is no-throw invocable with the specified return and argument types.
ARENE_NODISCARD auto on_scope_exit(CallableType &&func) noexcept(std::is_nothrow_constructible< remove_cvref_t< CallableType >, CallableType >::value) -> scope_guard< remove_cvref_t< CallableType > >
Declarative helper for constructing scope_guard instances.
Definition scope_guard.hpp:122
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
remove_cv_t< remove_reference_t< T > > remove_cvref_t
Backport of std::remove_cvref_t.
Definition remove_cvref.hpp:35
Definition accumulate.hpp:36
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
constexpr auto exchange(T &target, U &&source) noexcept(is_nothrow_move_constructible_v< T > &&is_nothrow_assignable_v< T &, U && >) -> T
Assign a new value to an object and return the old value. Implements std::exchange.
Definition exchange.hpp:33
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26