shared: move ScopeExit from riscv64 arch kernel code

this file is c++11 only.

Change-Id: Ibff7acec00337a9f56f9b8e29ea262c8d64c2446
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5292
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Fredrik Holmqvist <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
X512
2022-09-21 16:09:33 +00:00
committed by Jérôme Duval
parent b4d0fd9177
commit 74a5cb7bbc
2 changed files with 45 additions and 35 deletions
+43
View File
@@ -0,0 +1,43 @@
/*
* Copyright 2022, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SCOPE_EXIT_H
#define _SCOPE_EXIT_H
#if __cplusplus < 201103L
#error This file requires compiler support for the C++11 standard.
#endif
#include <utility>
template<typename F>
class ScopeExit
{
public:
explicit ScopeExit(F&& fn) : fFn(fn)
{
}
~ScopeExit()
{
fFn();
}
ScopeExit(ScopeExit&& other) : fFn(std::move(other.fFn))
{
}
private:
ScopeExit(const ScopeExit&);
ScopeExit& operator=(const ScopeExit&);
private:
F fFn;
};
#endif // _SCOPE_EXIT_H