From cec79a3f5578da4a9f9085282389482edf45c81b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 16 Mar 2025 12:48:45 +0100 Subject: New upstream version 4.26 --- doc/scope.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 doc/scope.rst (limited to 'doc/scope.rst') diff --git a/doc/scope.rst b/doc/scope.rst new file mode 100644 index 0000000..84ad69b --- /dev/null +++ b/doc/scope.rst @@ -0,0 +1,22 @@ +============ +Scope guards +============ + +``scope_exit`` +============== + +scope_exit creates an object that runs a predefined function when a scope ends. +This is useful for augmenting C APIs with something of a destructor without +wrapping the stuff in an explicit class of its own. For instance, + +.. code-block:: c++ + + #include + #include + int main() { + auto fa = HXformat_init(); + if (fa == nullptr) + return 0; + auto cleanup_fa = HX::make_scope_exit([&]() { HXformat_free(fa); }); + HXformat_add(fa, "foo", "bar", HXTYPE_STRING); + } -- cgit v1.2.3