#include <muu/scope_guard.h>
template <typename T>
scope_guard class
Performs actions when going out of scope.
Template parameters | |
---|---|
T | A noexcept function, lambda or other callable not requiring any arguments (e.g. void() noexcept )`. |
Use a scope_
void do_work() { acquire_magic_lock(); muu::scope_guard sg{ release_magic_lock }; something_that_throws(); }
For comparison's sake, here's the same function without a scope_
void do_work() { acquire_magic_lock(); try { something_that_throws(); } catch (...) { release_magic_lock(); throw; } release_magic_lock(); }
Constructors, destructors, conversion operators
-
template <typename U>scope_guard(U&& func) explicit noexcept(…)
- Constructs a scope_
guard by wrapping a callable.
Public functions
Function documentation
template <typename T>
template <typename U>
muu::scope_guard::scope_guard(U&& func) explicit noexcept(…)
template <typename U>
Constructs a scope_
Template parameters | |
---|---|
U | A function, lambda or other callable with the signature void() noexcept . |
Parameters | |
func | The callable to invoke when the scope_ |