www.digitalmars.com         C & C++   DMDScript  

c++.chat - D-style scope(failure) and scope(success) in C++

try
{
     int some_var=1;

     scope(exit)
     {
         cout << "exit " << some_var << endl;
         ++some_var;
     };
     scope(failure)
     {
         cout << "failure " << some_var  << endl;
         ++some_var;
     };
     scope(success)
     {
         cout << "success " << some_var  << endl;
         ++some_var;
     };
     throw 1;
} catch(int){}

https://github.com/panaseleus/stack_unwinding#d-style-scope-guardsactions
https://github.com/panaseleus/stack_unwinding/blob/master/examples/example_from_dlang_dot_org.cpp
https://github.com/panaseleus/stack_unwinding/blob/master/examples/boost_scopes.cpp
https://github.com/panaseleus/stack_unwinding/blob/master/examples/boost_scopes_cpp11.cpp
Oct 13 2012