mirror of
https://github.com/intel/llvm.git
synced 2026-01-23 07:58:23 +08:00
[orc-rt] Use perfect forwarding for scope-exit initialization. (#157786)
Allows the use of move-only types with make_scope_exit.
This commit is contained in:
@@ -21,7 +21,8 @@ namespace detail {
|
||||
|
||||
template <typename Fn> class ScopeExitRunner {
|
||||
public:
|
||||
ScopeExitRunner(Fn &&F) : F(F) {}
|
||||
template <typename FnInit>
|
||||
ScopeExitRunner(FnInit &&F) : F(std::forward<FnInit>(F)) {}
|
||||
ScopeExitRunner(const ScopeExitRunner &) = delete;
|
||||
ScopeExitRunner &operator=(const ScopeExitRunner &) = delete;
|
||||
ScopeExitRunner(ScopeExitRunner &&) = delete;
|
||||
|
||||
@@ -37,3 +37,15 @@ TEST(ScopeExitTest, Release) {
|
||||
}
|
||||
EXPECT_FALSE(ScopeExitRun);
|
||||
}
|
||||
|
||||
TEST(ScopeExitTest, MoveOnlyFunctionObject) {
|
||||
struct MoveOnly {
|
||||
MoveOnly() = default;
|
||||
MoveOnly(MoveOnly &&) = default;
|
||||
void operator()() {}
|
||||
};
|
||||
|
||||
{
|
||||
auto OnExit = make_scope_exit(MoveOnly());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user