aboutsummaryrefslogtreecommitdiff
path: root/gdb/common/forward-scope-exit.h
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2019-01-23 18:58:29 +0000
committerPedro Alves <palves@redhat.com>2019-01-23 19:02:58 +0000
commit54b65c9b51ec80ef5812dde1a508ce171eeb8ce6 (patch)
tree599f1e4e5d1c0764ba445f46fc12834cac54f83b /gdb/common/forward-scope-exit.h
parentcf08fb29f8c484a34c4babb015348b220f80a33b (diff)
downloadbinutils-54b65c9b51ec80ef5812dde1a508ce171eeb8ce6.zip
binutils-54b65c9b51ec80ef5812dde1a508ce171eeb8ce6.tar.gz
binutils-54b65c9b51ec80ef5812dde1a508ce171eeb8ce6.tar.bz2
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.
Diffstat (limited to 'gdb/common/forward-scope-exit.h')
0 files changed, 0 insertions, 0 deletions