MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
mostly_harmless::utils::OnScopeExit Class Referencefinal

Functor to run some code when this variable goes out of scope. More...

#include <mostlyharmless_OnScopeExit.h>

Public Member Functions

 OnScopeExit (std::function< void(void)> &&action)
 
 ~OnScopeExit () noexcept
 

Detailed Description

Functor to run some code when this variable goes out of scope.

Useful for performing some action after a function returns, for example:

void sayHiOnExit() {
OnScopeExit se { []() -> void {
std::cout << "Hello world!\n";
}};
// function body etc etc etc
}
OnScopeExit(std::function< void(void)> &&action)

Will print "Hello world" after the function body has run.

Lifetime concerns apply here, be very very careful.

Constructor & Destructor Documentation

◆ OnScopeExit()

mostly_harmless::utils::OnScopeExit::OnScopeExit ( std::function< void(void)> && action)
explicit

Constructs an OnScopeExit.

Parameters
actionAn rvalue ref to an action to perform when this object gets destroyed.

◆ ~OnScopeExit()

mostly_harmless::utils::OnScopeExit::~OnScopeExit ( )
noexcept

Destructor - the lambda you passed to the constructor will be executed here.


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