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