Execution of code when a scope is left

You can execute code when the enclosing scope is left by using the macro ARMARX_ON_SCOPE_EXIT. Later macro instantiations are executed first (order of c++ stack unwinding).

{
{
std::cout<<"bar";
}
{
std::cout<<"foo";
}
std::cout << "baz"; //prints "baz"
}//prints "foo" then "bar"

This code prints "bazfoobar" on std::cout. ("foobar" is printed when the scope is left).

ARMARX_ON_SCOPE_EXIT
#define ARMARX_ON_SCOPE_EXIT
Executes given code when the enclosing scope is left.
Definition: OnScopeExit.h:112