Details
-
Task
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
Description
std::scope_exit is a generic RAII wrapper over any callable (callable class, lambda, function). It calls it's function at the scope end. You can find more information in http://wg21.link/p0052
A typical usage is freeing resources. Imagine some function where you do malloc() at the beginning and later on free() at three different places before each return;. With scope guard you can just do something like
auto _ = std::make_scope_guard([ptr]() { free(ptr); });
|
once soon after allocating and forget about possibly memory leaks.
Attachments
Issue Links
- relates to
-
MDEV-22441 implement a generic way to change a value of a variable in a scope
- In Review