12#ifndef OPENVPN_COMMON_CLEANUP_H
13#define OPENVPN_COMMON_CLEANUP_H
34 requires std::invocable<F>
38 explicit CleanupType(F method)
noexcept(std::is_nothrow_move_constructible_v<F>)
39 :
clean(std::move(method))
45 :
clean(std::exchange(other.clean, std::nullopt))
52 clean = std::exchange(other.clean, std::nullopt);
99 std::optional<std::function<void()>>
release() noexcept
103 std::function<void()> func = std::move(*
clean);
123 requires std::invocable<F>
A scope guard that runs a callable on destruction unless dismissed or released.
CleanupType & operator=(const CleanupType &)=delete
CleanupType(F method) noexcept(std::is_nothrow_move_constructible_v< F >)
std::optional< std::function< void()> > release() noexcept
Release the cleanup action, returning the callable and preventing it from being executed on destructi...
void dismiss() noexcept
Dismiss the cleanup action, preventing it from being executed on destruction.
CleanupType(const CleanupType &)=delete
~CleanupType() noexcept
Destructor that executes the cleanup action if not dismissed or released.
CleanupType & operator=(CleanupType &&other) noexcept
CleanupType(CleanupType &&other) noexcept
CleanupType< F > Cleanup(F method) noexcept(std::is_nothrow_move_constructible_v< F >)
Factory function to create a CleanupType object.