2016-04-29 11:57:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-03-27 01:12:25 +00:00
|
|
|
/**
|
|
|
|
* A trivial class to run a function at the end of a scope.
|
|
|
|
*/
|
2021-12-30 23:50:23 +00:00
|
|
|
template<typename Fn>
|
2016-04-29 11:57:08 +00:00
|
|
|
class Finally
|
|
|
|
{
|
|
|
|
private:
|
2021-12-30 23:50:23 +00:00
|
|
|
Fn fun;
|
2016-04-29 11:57:08 +00:00
|
|
|
|
|
|
|
public:
|
2021-12-30 23:50:23 +00:00
|
|
|
Finally(Fn fun) : fun(std::move(fun)) { }
|
2016-04-29 11:57:08 +00:00
|
|
|
~Finally() { fun(); }
|
|
|
|
};
|