Skip to content

Commit 111fb37

Browse files
authored
Remove swift::DoAtScopeExit in favor of llvm::make_scope_exit (#27113)
Keep the SWIFT_DEFER macro, though, which is what everyone in the Swift codebase actually uses. No functionality change.
1 parent 6663800 commit 111fb37

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

include/swift/Basic/Defer.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,15 @@
1818
#ifndef SWIFT_BASIC_DEFER_H
1919
#define SWIFT_BASIC_DEFER_H
2020

21-
#include <type_traits>
21+
#include "llvm/ADT/ScopeExit.h"
2222

2323
namespace swift {
24-
template <typename F>
25-
class DoAtScopeExit {
26-
F Fn;
27-
void operator=(DoAtScopeExit&) = delete;
28-
public:
29-
DoAtScopeExit(F &&Fn) : Fn(std::move(Fn)) {}
30-
~DoAtScopeExit() {
31-
Fn();
32-
}
33-
};
34-
3524
namespace detail {
3625
struct DeferTask {};
3726
template<typename F>
38-
DoAtScopeExit<typename std::decay<F>::type> operator+(DeferTask, F&& fn) {
39-
return DoAtScopeExit<typename std::decay<F>::type>(std::move(fn));
27+
auto operator+(DeferTask, F &&fn) ->
28+
decltype(llvm::make_scope_exit(std::forward<F>(fn))) {
29+
return llvm::make_scope_exit(std::forward<F>(fn));
4030
}
4131
}
4232
} // end namespace swift

0 commit comments

Comments
 (0)