[MDEV-22438] add a function similar to std::make_scope_exit() Created: 2020-05-03 Updated: 2020-07-02 Resolved: 2020-06-22 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Server |
| Fix Version/s: | 10.4.14, 10.5.5 |
| Type: | Task | Priority: | Major |
| Reporter: | Eugene Kosov (Inactive) | Assignee: | Eugene Kosov (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| 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
once soon after allocating and forget about possibly memory leaks. |
| Comments |
| Comment by Sergei Golubchik [ 2020-05-03 ] |
|
please also create a specialized template for a common case when one needs to change variable's value in a scope. Like, temporarily change the sql mode or thd options, etc |