4 ms·
You can do the same thing with no C++11 features other than C99 variadic macros. (IMO cleaner, too). #define SCOPE_EXIT(...)\ struct SE##__LINE__##_{~SE##
by smitherfield 9y ago
You can do the same thing with no C++11 features other than C99 variadic macros. (IMO cleaner, too).
#define SCOPE_EXIT(...)\
struct SE##__LINE__##_{~SE##__LINE__##_(){__VA_ARGS__;}}se##__LINE__##_
- saagarjha 9y agoI'm curious: is __VA_ARGS__ part of the standard, or just widely used?
- tzahola 9y agoYeah but that’s kinda cheating
- mehrdadn 9y agoNo, you can't generally put anything useful in there. The whole point of a lambda is the [&]. If you can't capture local variables then it's practically useless.
- maxlybbert 9y agoAlexandrescu managed to do it in 2000: http://www.drdobbs.com/article/print?articleId=184403758&siteSectionName=cpp http://www.drdobbs.com/article/print?articleId=184403758&sit... (note that there are three pages). The version in Facebook Folly was cleaned up because of C++11, but this wasn’t a new technique five years ago.