Hi,
but why? You have RAII, use it. It's the proper way to deal with resource cleanup.
struct _finally()
{
_finally(std::function<void(void)> f) _f(f) : {}
~_finally() ( _f(); };
std::function<void(void)> _f;
};
my_function() {
// let's define our finally
_finally f([](){
cleanup();
});
try {
} catch(...) {}
// whatever.
} // here your _finally will be destroyed, which will call the d'tor ~_finally() and your lambda in d'tor will be called.
But this is a lazy bodge. You could nicely encapsulate your resource as a class and get RAII out of the box.
BR,
Igor