Introduce 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:02:58 +0000 (19:02 +0000)
commit54b65c9b51ec80ef5812dde1a508ce171eeb8ce6
tree599f1e4e5d1c0764ba445f46fc12834cac54f83b
parentcf08fb29f8c484a34c4babb015348b220f80a33b
Introduce scope_exit

This add a new template class scope_exit.  scope_exit is a
general-purpose scope guard that calls its exit function at the end of
the current scope.  A scope_exit may be canceled by calling the
"release" method.  The API is modeled on P0052R5 - Generic Scope Guard
and RAII Wrapper for the Standard Library, which is itself based on
Andrej Alexandrescu's ScopeGuard/SCOPE_EXIT.

The main advantage of scope_exit is avoiding writing single-use RAII
classes and its boilerplate.  Following patches will remove a few of
such classes.

There are two forms available:

 - The "make_scope_exit" form allows canceling the scope guard.  Use
   it like this:

     auto cleanup = make_scope_exit ( <function, function object, lambda> );
     ...
     cleanup.release (); // cancel

 - If you don't need to cancel the guard, you can use the SCOPE_EXIT
   macro, like this:

     SCOPE_EXIT { /* any code you like here. */ }

Note: scope_exit instances do not allocate anything on the heap.

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

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