summaryrefslogtreecommitdiff
path: root/doc/scope.rst
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2025-03-16 12:48:47 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2025-03-16 12:48:47 +0100
commit3aa2b0a6657b0ebd1618ee684f8ae31cd8bf127b (patch)
tree42a3aaef992613eab55c5154ca7d207a4f70ef99 /doc/scope.rst
parent5acefbd715c8720abc5d8ccd5349e1d9589739df (diff)
parentcec79a3f5578da4a9f9085282389482edf45c81b (diff)
Update upstream source from tag 'upstream/4.26'
Update to upstream version '4.26' with Debian dir 21e0b48e0d5c4f3b261c10cb65f0ca9fa00fd732
Diffstat (limited to 'doc/scope.rst')
-rw-r--r--doc/scope.rst22
1 files changed, 22 insertions, 0 deletions
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 <libHX/option.h>
+ #include <libHX/scope.hpp>
+ 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);
+ }