Introduce forward_scope_exit
authorPedro Alves <palves@redhat.com>
Wed, 23 Jan 2019 18:58:29 +0000 (18:58 +0000)
committerPedro Alves <palves@redhat.com>
Wed, 23 Jan 2019 19:03:20 +0000 (19:03 +0000)
commit5b9b3e53a68f4568dc0b6907e34e763a6c3dd145
tree88330e51c94cb494319813787fe23e42abeee4b1
parent54b65c9b51ec80ef5812dde1a508ce171eeb8ce6
Introduce forward_scope_exit

This adds a template that can be used to automatically instantiate
scope_exit-like types that wrap some cleanup function.  The
instantiated type has a ctor that has the same interface as the
wrapped function.  While the "magic" is just straight C++11, the
intended use is via the FORWARD_SCOPE_EXIT macro, which is a minimal
macro that avoids spelling out the wrapped function name more than
once:

 void some_function (int foo, object *bar);
 using some_function_fce = FORWARD_SCOPE_EXIT (some_function);
 some_function_fce cleanup (some_int, some_obj_ptr);

The above runs:
  some_function (some_int, some_obj_ptr);
at scope exit.

This is mainly useful as opposed to a simpler SCOPE_EXIT when you need
to:
  - cancel the scope_exit, in which case you need the object's name
  - wrap the scope_exit in a gdb::optional, in which case you need the
    scope_exit's type in advance.

More details in the code comments.

gdb/ChangeLog:
2019-01-23  Pedro Alves  <palves@redhat.com>
    Andrew Burgess  <andrew.burgess@embecosm.com>

* common/forward-scope-exit.h: New file.
gdb/ChangeLog
gdb/common/forward-scope-exit.h [new file with mode: 0644]
This page took 0.0267230000000001 seconds and 4 git commands to generate.