Skip to content

Instantly share code, notes, and snippets.

@michaelcontento
Last active December 18, 2015 11:28
Show Gist options
  • Select an option

  • Save michaelcontento/047edb057781e0f73c43 to your computer and use it in GitHub Desktop.

Select an option

Save michaelcontento/047edb057781e0f73c43 to your computer and use it in GitHub Desktop.
template<typename T>
class FinalAction
{
FinalAction(T f): clean(f) {}
~FinalAction() { clean(); }
T clean;
}
template<typename T>
FinalAction<T> finally(T f)
{
return FinalAction<T>(f);
}
void test()
{
int* p = new int(7);
auto f = finally([&p]() { delete p; });
throw std::runtime_error("foo!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment