2016-04-29 13:57:08 +02:00
|
|
|
#pragma once
|
|
|
|
|
2016-11-07 14:35:47 +01:00
|
|
|
#include <functional>
|
|
|
|
|
2016-04-29 13:57:08 +02:00
|
|
|
/* A trivial class to run a function at the end of a scope. */
|
2020-05-17 16:31:57 +01:00
|
|
|
class Finally {
|
|
|
|
private:
|
|
|
|
std::function<void()> fun;
|
2016-04-29 13:57:08 +02:00
|
|
|
|
2020-05-17 16:31:57 +01:00
|
|
|
public:
|
2020-08-21 04:00:55 +01:00
|
|
|
explicit Finally(std::function<void()> fun) : fun(fun) {}
|
2020-05-17 16:31:57 +01:00
|
|
|
~Finally() { fun(); }
|
2016-04-29 13:57:08 +02:00
|
|
|
};
|