Wraps a closure that is invoked in the destructor unless released by the caller.
More...
Wraps a closure that is invoked in the destructor unless released by the caller.
This is especially useful in dealing with APIs that return a resource by accepting ownership of a sub-resource and a closure that releases that resource. When such APIs are chained, each link in the chain must check that the next member in the chain has accepted the resource. If not, it must invoke the closure eagerly. Not doing this results in a resource leak in the erroneous case. Using this wrapper, the closure can be released once the next call in the chain has successfully accepted ownership of the resource. If not, the closure gets invoked automatically at the end of the scope. This covers the cases where there are early returns as well.
Definition at line 32 of file closure.h.