1/*
2 * Copyright 2022, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _SCOPE_EXIT_H
6#define _SCOPE_EXIT_H
7
8
9#if __cplusplus < 201103L
10#error This file requires compiler support for the C++11 standard.
11#endif
12
13
14#include <utility>
15
16
17template<typename F>
18class ScopeExit
19{
20public:
21	explicit ScopeExit(F&& fn) : fFn(fn)
22	{
23	}
24
25	~ScopeExit()
26	{
27		fFn();
28	}
29
30	ScopeExit(ScopeExit&& other) : fFn(std::move(other.fFn))
31	{
32	}
33
34private:
35	ScopeExit(const ScopeExit&);
36	ScopeExit& operator=(const ScopeExit&);
37
38private:
39	F fFn;
40};
41
42
43#endif // _SCOPE_EXIT_H
44