Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::utils::Defer< F > Class Template Reference

A utility class that defers the execution of a callable until the object goes out of scope. More...

#include <defer.hpp>

Public Member Functions

 Defer ()=delete
constexpr Defer (F func) noexcept(std::is_nothrow_move_constructible_v< F >)
 Constructs a Defer object that will execute the provided callable upon destruction.
 Defer (Defer &&)=delete
 Defer (const Defer &)=delete
constexpr ~Defer () noexcept(std::is_nothrow_invocable_v< F >)
Deferoperator= (const Defer &)=delete
Deferoperator= (Defer &&)=delete

Detailed Description

template<std::invocable F>
class helios::utils::Defer< F >

A utility class that defers the execution of a callable until the object goes out of scope.

Template Parameters
FThe type of the callable to be executed upon destruction.
// Pattern 1: Pre-defined lambda
auto cleanup = [resource]() { delete resource; };
// Pattern 2: Inline lambda (no capture list needed)
delete resource;
};
#define HELIOS_DEFER
Defers execution of an inline lambda until the end of the current scope.
Definition defer.hpp:82
#define HELIOS_DEFER_CALL(callable)
Defers execution of a callable until the end of the current scope.
Definition defer.hpp:98

Definition at line 29 of file defer.hpp.

Constructor & Destructor Documentation

◆ Defer() [1/4]

template<std::invocable F>
helios::utils::Defer< F >::Defer ( )
delete

◆ Defer() [2/4]

template<std::invocable F>
helios::utils::Defer< F >::Defer ( F func)
inlineexplicitconstexprnoexcept

Constructs a Defer object that will execute the provided callable upon destruction.

Parameters
funcThe callable to be executed.

Definition at line 38 of file defer.hpp.

◆ Defer() [3/4]

template<std::invocable F>
helios::utils::Defer< F >::Defer ( Defer< F > && )
delete

◆ Defer() [4/4]

template<std::invocable F>
helios::utils::Defer< F >::Defer ( const Defer< F > & )
delete

◆ ~Defer()

template<std::invocable F>
helios::utils::Defer< F >::~Defer ( )
inlineconstexprnoexcept

Definition at line 43 of file defer.hpp.

Member Function Documentation

◆ operator=() [1/2]

template<std::invocable F>
Defer & helios::utils::Defer< F >::operator= ( const Defer< F > & )
delete

◆ operator=() [2/2]

template<std::invocable F>
Defer & helios::utils::Defer< F >::operator= ( Defer< F > && )
delete