| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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:11
final_action::~final_action
~final_action()
Definition: finally.h:14
final_action::act
F act
Definition: finally.h:12
final_action::final_action
final_action(final_action &&)=default