Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
finally.h
Go to the documentation of this file.
1 #pragma once
2 #include <functional>
3 
4 namespace hgps {
5 
8 template <typename F> class Finally {
9  public:
13  template <typename Func> Finally(Func &&func) : functor_(std::forward<Func>(func)) {}
14 
15  Finally(const Finally &) = delete;
16  Finally(Finally &&) = delete;
17  Finally &operator=(const Finally &) = delete;
18  Finally &operator=(Finally &&) = delete;
19 
22  try {
23  functor_();
24  } catch (...) {
25  }
26  }
27 
28  private:
29  F functor_;
30 };
31 
36 template <typename F> Finally<F> make_finally(F &&f) { return {std::forward<F>(f)}; }
37 } // namespace hgps
Define a scoped reset state data type.
Definition: finally.h:8
Finally(Func &&func)
Initialises a new instance of the Finally class.
Definition: finally.h:13
Finally(const Finally &)=delete
Finally(Finally &&)=delete
Finally & operator=(Finally &&)=delete
~Finally()
Destroys a Finally instance.
Definition: finally.h:21
Finally & operator=(const Finally &)=delete
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
Finally< F > make_finally(F &&f)
Makes a finally instance.
Definition: finally.h:36
Global namespace.
Definition: jsonparser.h:88