Last active
December 18, 2015 11:28
-
-
Save michaelcontento/047edb057781e0f73c43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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