[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:
Relates
relates to MDEV-22441 implement a generic way to change a v... In Review

 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.



 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

Generated at Thu Feb 08 09:14:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.