ScopeExit is a general-purpose scope proctor class template that is intended to be used as an automatic (stack) variable that calls an exit function upon its destruction (when its scope is exited).
Declared in <bdlb_scopeexit.h>
template<class EXIT_FUNC>
class [[nodiscard]] ScopeExit;
The template argument EXIT_FUNC shall be a function object type, or a pointer to a function. If EXIT_FUNC is an object type, it shall satisfy the requirements of Destructible, Callable, and MoveConstructible as specified by the ISO C++ standard. Note that to fulfill the MoveConstructible constraint a type does not have to implement a move constructor. If it has a copy constructor, that will work fine as long at the move constructor is not deleted (or in case of C++03 emulated moves, private). The behavior is undefined if calling (the member instance of) EXIT_FUNC throws an exception (as it will be called from the destructor).
| Name | Description |
|---|---|
ScopeExit [constructor] | Constructors |
~ScopeExit [destructor] | Destroy this object. Execute the exit function unless release() has been called on this object. |
release | Turn off the execution of the exit function of this object on destruction. |
| Name | Description |
|---|---|
ScopeExit<bsl::decay<EXIT_FUNC_PARAM>::type> | Deduce the template parameter EXIT_FUNC from the type of the callable passed to the constructor of ScopeExit. |
The return value should not be discarded.