Boost has ScopeExit library - I think it should be well tested.
It works on old compilers, with C++98. Also it supports C++11 lambdas when they are available, but unfortunately that case is not optimally implemented - because it stores lambda in boost::function which may cause costly allocation due to type erasure.
Folly's ScopeGuard uses type deduction as Andrei described in his talk.
I have made platform-specific implementation of uncaught_exception_count function year ago. It works on many versions of major compilers(actually on all versions that I have tested) and allows to determine whenever destructor was called due to stack-unwinding or due to "normal" scope leaving.
It is possible to implement scope(failure/success) features from D language based on top of such unwinding indicator. scope(failure/success) is basically scope guard without need to dismiss/commit manually at each exit point of scope.
Here is proof-of-concept implementation of scope(exit/success/failure) in C++11, example of usage at the bottom. Syntax is very close to D language.
epanasyuk5 karma
Boost has ScopeExit library - I think it should be well tested. It works on old compilers, with C++98. Also it supports C++11 lambdas when they are available, but unfortunately that case is not optimally implemented - because it stores lambda in boost::function which may cause costly allocation due to type erasure. Folly's ScopeGuard uses type deduction as Andrei described in his talk.
I have made platform-specific implementation of uncaught_exception_count function year ago. It works on many versions of major compilers(actually on all versions that I have tested) and allows to determine whenever destructor was called due to stack-unwinding or due to "normal" scope leaving.
It is possible to implement scope(failure/success) features from D language based on top of such unwinding indicator. scope(failure/success) is basically scope guard without need to dismiss/commit manually at each exit point of scope.
Here is proof-of-concept implementation of scope(exit/success/failure) in C++11, example of usage at the bottom. Syntax is very close to D language.
View HistoryShare Link