iffl  1.3.4
Implements Intrusive Flat Forward List container
Public Member Functions | List of all members
iffl::scope_guard< G > Class Template Reference

template class that can be parametrized with a functor or a lambda that it will call in destructor. More...

#include <iffl_common.h>

Inheritance diagram for iffl::scope_guard< G >:

Public Member Functions

constexpr scope_guard (G const &g)
 Constructor from an instance of functor. More...
 
constexpr scope_guard (G &&g)
 Constructor from an instance of functor. More...
 
constexpr scope_guard (scope_guard &&)=default
 Guard supports moving between scopes.
 
constexpr scope_guardoperator= (scope_guard &&)=default
 Guard supports moving between scopes.
 
constexpr scope_guard (scope_guard &)=delete
 Guard does not support copy.
 
constexpr scope_guardoperator= (scope_guard &)=delete
 Guard does not support copy.
 
 ~scope_guard () noexcept
 Destructor attempts to call functor if guard was not disarmed.
 
void discharge () noexcept
 Use this method to discharge guard now.
 
constexpr void disarm () noexcept
 Disarming guard tells it not discharge during destruction.
 
constexpr void arm () noexcept
 Can be used to re-arm guard after prior disarm or discharge.
 
constexpr bool is_armed () const noexcept
 Tells if guard is armed. More...
 
constexpr operator bool () const noexcept
 Implicit conversion to bool. More...
 

Detailed Description

template<typename G>
class iffl::scope_guard< G >

template class that can be parametrized with a functor or a lambda that it will call in destructor.

Used to execute functor as we are leaving scope, unless it was explicitly disarmed. flat_forward_list uses this helper to deallocate memory on failures. scoped_guald inherits from the functor to minimize type size when functor is an empty type. For more information see Empty Base Class Optimization (EBCO).

Template Parameters
Gtype of functor or a lambda

Constructor & Destructor Documentation

◆ scope_guard() [1/2]

template<typename G >
constexpr iffl::scope_guard< G >::scope_guard ( G const &  g)
inlineexplicit

Constructor from an instance of functor.

Parameters
g- guard we are syncing to the guard

◆ scope_guard() [2/2]

template<typename G >
constexpr iffl::scope_guard< G >::scope_guard ( G &&  g)
inlineexplicit

Constructor from an instance of functor.

Parameters
g- guard we are syncing to the guard

Member Function Documentation

◆ is_armed()

template<typename G >
constexpr bool iffl::scope_guard< G >::is_armed ( ) const
inlinenoexcept

Tells if guard is armed.

Returns
true if guard is armed and false otherwise

◆ operator bool()

template<typename G >
constexpr iffl::scope_guard< G >::operator bool ( ) const
inlineexplicitnoexcept

Implicit conversion to bool.

Returns
true if guard is armed and false otherwise

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