Public Member Functions | List of all members
MovableOnScopeExit Class Referencefinal

Run a function on scope exit (movable version). More...

#include <MovableOnScopeExit.hpp>

Public Member Functions

template<typename FunctionT >
 MovableOnScopeExit (FunctionT function)
 Run the function on scope exit. More...
 
 MovableOnScopeExit (MovableOnScopeExit &&rhs) noexcept
 Move the scope exit running to a different instance. More...
 
void clear ()
 Set to the function to NOP (cancels scheduled execution). More...
 
void executeNow ()
 Execute the function now and then clear it. More...
 

Detailed Description

Run a function on scope exit (movable version).

This class should be used as a stack based instance. The template constructor takes a function pointer or lambda expression. This function is run when the scope within which the instance is defined exits, unless the instance is moved out of the scope.

If the instance is moved, the old instance will not run the function on destruction. This allows the instance to be set up in an inner scope and moved to the calling scope without the function running at the end of the inner scope.

Constructor & Destructor Documentation

◆ MovableOnScopeExit() [1/2]

MovableOnScopeExit ( FunctionT  function)
inlineexplicit

Run the function on scope exit.

◆ MovableOnScopeExit() [2/2]

MovableOnScopeExit ( MovableOnScopeExit &&  rhs)
inlinenoexcept

Move the scope exit running to a different instance.

Member Function Documentation

◆ clear()

void clear ( )
inline

Set to the function to NOP (cancels scheduled execution).

◆ executeNow()

void executeNow ( )
inline

Execute the function now and then clear it.


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