The Gaudi Framework  v29r0 (ff2e7097)
finally.h
Go to the documentation of this file.
1 #include <utility>
2 //
3 // make it possible to execute an action at the exit of a scope
4 //
5 // auto f = finally( [](){ std::cout << "end of scope!" << std::endl; } );
6 //
7 // the above will execute the provided callable when f goes out of scope,
8 // i.e. the 'current' scope ends.
9 
10 template <typename F>
11 struct final_action {
12  F act;
13  final_action( final_action&& ) = default;
14  ~final_action() { act(); }
15 };
16 
17 template <typename F>
18 final_action<F> finally( F&& act )
19 {
20  return {std::forward<F>( act )};
21 }
~final_action()
Definition: finally.h:14
final_action(final_action &&)=default