PIP 5.5.3
Platform-Independent Primitives
Public Member Functions | List of all members
PIScopeExitCall Class Reference

Class for executing a function upon scope exit. More...

#include <pibase.h>

Public Member Functions

 PIScopeExitCall (std::function< void()> f)
 Constructor that takes a function to execute.
 
 ~PIScopeExitCall ()
 Destructor that executes the function if it exists.
 
void cancel ()
 Method for canceling the function.
 
void call ()
 Method for call the function.
 
void callAndCancel ()
 Method for call and canceling the function.
 

Detailed Description

Class for executing a function upon scope exit.

Example

bool yourFunc() {
PIScopeExitCall error_call([]() { piCout << "Error!"; });
...
if (!good0) {
...
return false;
}
if (!good1) {
...
return false;
}
...
error_call.cancel();
return true;
}
Class for executing a function upon scope exit.
Definition: pibase.h:686
void cancel()
Method for canceling the function.
Definition: pibase.h:701
#define piCout
Macro used for conditional (piDebug) output to PICout(StdOut)
Definition: picout.h:35

In this example "Error!" will be printed on every false function return.