PIP 6.1.0
Platform-Independent Primitives
Loading...
Searching...
No Matches
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;
}
PIScopeExitCall(std::function< void()> f)
Constructor that takes a function to execute.
Definition pibase.h:735
#define piCout
Macro used for conditional (piDebug) output to PICout(StdOut).
Definition picout.h:36

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