Created
July 25, 2015 15:30
-
-
Save xiaosuo/17ba37a7a884994ebbde 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
class Defer { | |
public: | |
explicit Defer(std::function<void()> func) : func_(func) {} | |
~Defer() { func_(); } | |
private: | |
Defer(const Defer &) = delete; | |
Defer& operator=(const Defer &) = delete; | |
std::function<void()> func_; | |
}; | |
#define ____defer(func, line) Defer __defer_##line(func) | |
#define __defer(func, line) ____defer(func, line) | |
#define defer(func) __defer(func, __LINE__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment