Created
July 14, 2023 15:18
-
-
Save nickav/c677d7fdfdce1279c3d5a0f8cd06bd09 to your computer and use it in GitHub Desktop.
defer macro thing
This file contains 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
#ifndef defer | |
// Defer macro/thing. | |
template<typename T> | |
struct ExitScope { | |
T lambda; | |
ExitScope(T lambda) : lambda(lambda) {} | |
~ExitScope() { lambda(); } | |
ExitScope(const ExitScope&); | |
private: | |
ExitScope& operator =(const ExitScope&); | |
}; | |
class ExitScopeHelp { | |
public: | |
template<typename T> | |
ExitScope<T> operator+(T t) { return t; } | |
}; | |
#define defer const auto& CONCAT(defer__, __LINE__) = ExitScopeHelp() + [&]() | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment