Public Member Functions | List of all members
kvikio::detail::ScopeExit< F > Class Template Reference

A simple scope guard that invokes a cleanup callable upon destruction. More...

#include <utils.hpp>

Public Member Functions

 ScopeExit (F &&cleanup)
 Constructs a scope guard that will invoke cleanup on destruction. More...
 
 ScopeExit (ScopeExit const &)=delete
 
ScopeExitoperator= (ScopeExit const &)=delete
 
 ScopeExit (ScopeExit &&)=delete
 
ScopeExitoperator= (ScopeExit &&)=delete
 

Detailed Description

template<typename F>
class kvikio::detail::ScopeExit< F >

A simple scope guard that invokes a cleanup callable upon destruction.

Guarantees the cleanup action runs when the guard goes out of scope, regardless of how the scope is exited (normal return or exception). If the cleanup itself throws an exception, it is suppressed to avoid calling std::terminate.

Usage:

detail::ScopeExit guard([&]() { release(resource); });
// Or
auto guard = ScopeExit([&]() { release(resource); });
ScopeExit(F &&cleanup)
Constructs a scope guard that will invoke cleanup on destruction.
Template Parameters
FA callable type invocable with no arguments.

Definition at line 86 of file detail/utils.hpp.

Constructor & Destructor Documentation

◆ ScopeExit()

template<typename F >
kvikio::detail::ScopeExit< F >::ScopeExit ( F &&  cleanup)
inlineexplicit

Constructs a scope guard that will invoke cleanup on destruction.

Parameters
cleanupThe cleanup callable to invoke on destruction

Definition at line 97 of file detail/utils.hpp.


The documentation for this class was generated from the following file: