3 ms·
I disagree. If you tell people that the only way they can do something "on scope exit" is to write a whole class with a destructor and manually capturing varia
by kentonv 9y ago
I disagree.
If you tell people that the only way they can do something "on scope exit" is to write a whole class with a destructor and manually capturing variables, the result is they won't bother. They'll just put the code at the end of the function, and say "I'm too lazy to make this exception-safe."
This defer() macro is almost exactly what I've been using for the last 5 years or so:
https://github.com/capnproto/capnproto/blob/master/c++/src/kj/common.h#L1451 https://github.com/capnproto/capnproto/blob/master/c++/src/k...
And I can say pretty confidently that it's a really good idea to have. I'm sort of surprised, actually, that not everyone is already doing this...