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.