Create a scope guard.
Synopsis
Declared in <folly/ScopeGuard.h>
template<typename F>
[[nodiscard]]
/* implementation-defined */
makeGuard(F&& f) noexcept(/* see-below */);
Description
The returned object has methods .dismiss() and .rehire(), which will deactivate/reactivate the calling of the function upon destruction.
The return value of this function must be captured. Otherwise, since it is a temporary, it will be destroyed immediately, thus calling the function.
auto guard = makeGuard(...); // good
makeGuard(...); // bad
Exception specification
This function is potentially-throwing unless noexcept(detail::ScopeGuardImplDecay<F, true>(static_cast<F &&>(f))).
Return Value
A scope guard that runs f when it is destroyed. refcode folly/docs/examples/folly/ScopeGuard2.cpp
|
Note
|
The return value should not be discarded. |
Parameters
Name |
Description |
f |
The function to execute upon the guard's destruction. |
Created with MrDocs