Go to the documentation of this file.
9 #ifndef EAGINE_SCOPE_EXIT_HPP
10 #define EAGINE_SCOPE_EXIT_HPP
15 #include <type_traits>
23 template <
typename OnException = nothing_t>
31 : _action(std::move(action)) {}
34 template <
typename Func>
55 _invoke(OnException());
62 return _action.is_valid();
70 return std::move(_action);
84 void _invoke(std::true_type)
const {
86 if(std::uncaught_exceptions()) {
95 void _invoke(std::false_type)
const {
97 if(!std::uncaught_exceptions()) {
103 void _invoke(nothing_t)
const {
120 template <
typename Func,
typename OnException = nothing_t>
129 : _func(std::move(func))
143 template <
typename Func>
144 [[nodiscard]]
static inline auto finally(Func func)
151 #endif // EAGINE_SCOPE_EXIT_HPP
Declaration of class template storing a reference to a callable object.
Definition: callable_ref.hpp:24
on_scope_exit(action_type action) noexcept
Construction intializing with the specified action.
Definition: scope_exit.hpp:30
Common code is placed in this namespace.
Definition: eagine.hpp:21
on_scope_exit(on_scope_exit &&temp) noexcept
Move constructor.
Definition: scope_exit.hpp:39
auto operator=(on_scope_exit &&)=delete
Not move constructible.
func_on_scope_exit(Func func)
Initialization from the specified callable object.
Definition: scope_exit.hpp:128
callable_ref< void()> action_type
The callable action type.
Definition: scope_exit.hpp:27
Class executing a specified action on scope exit.
Definition: scope_exit.hpp:24
on_scope_exit(Func &action) noexcept
Construction intializing with the specified action.
Definition: scope_exit.hpp:35
Class storing a callable object and an instance of on_scope_exit.
Definition: scope_exit.hpp:121
~on_scope_exit() noexcept(false)
Invokes the stored action, unless it was released or cancelled.
Definition: scope_exit.hpp:54
auto release() noexcept -> action_type
Moves out and returns the stored action.
Definition: scope_exit.hpp:69
auto is_active() const noexcept -> bool
Indicates if there is any on-scope-exit action.
Definition: scope_exit.hpp:61
void cancel() noexcept
Cancels this on scope exit action.
Definition: scope_exit.hpp:133
void cancel() noexcept
Resets the stored action to empty default.
Definition: scope_exit.hpp:77