Hacker News new | past | comments | ask | show | jobs | submit login

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__##_



No, 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.


Alexandrescu managed to do it in 2000: 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.


I'm curious: is __VA_ARGS__ part of the standard, or just widely used?


It's part of the standards since C99 and C++11.


It is.


Yeah but that’s kinda cheating




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: