rstd 0.1.0
Loading...
Searching...
No Matches
rstd::mem::drop_guard::DropGuard< T, F > Struct Template Referenceexport
module rstd.core

A scope guard that invokes a callable on the inner value when dropped. More...

Public Member Functions

constexpr auto as_ptr () const noexcept
 Returns a const pointer to the guarded value.
 
constexpr auto as_mut_ptr () noexcept
 Returns a mutable pointer to the guarded value.
 

Static Public Member Functions

static auto make (T &&inner, F &&f) -> Self
 Creates a DropGuard wrapping the value and drop function.
 

Detailed Description

template<typename T, typename F>
struct rstd::mem::drop_guard::DropGuard< T, F >

A scope guard that invokes a callable on the inner value when dropped.

On destruction, the inner value is moved out and passed to the stored callable F. Useful for ensuring cleanup logic runs even when leaving scope via an exception.

Template Parameters
TThe guarded value type.
FA callable type invoked as f(T*) on drop.

Member Function Documentation

◆ make()

template<typename T , typename F >
static auto rstd::mem::drop_guard::DropGuard< T, F >::make ( T && inner,
F && f ) -> Self
inlinestatic

Creates a DropGuard wrapping the value and drop function.

Parameters
innerThe value to guard.
fThe callable invoked with a pointer to inner on destruction.
Returns
A new DropGuard.

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