[llvm] [LLVM][ADT] Make `scope-exit` CTAD-capable (PR #173131)
Victor Chernyakin via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 19 18:24:47 PST 2025
https://github.com/localspook created https://github.com/llvm/llvm-project/pull/173131
This enables using it like
```cpp
llvm::scope_exit Cleanup = [] { ... };
```
instead of
```cpp
auto Cleanup = llvm::make_scope_exit([] { ... });
```
>From 28d2310a4fd7f8aeed414934a819b4676a76cd9e Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <chernyakin.victor.j at outlook.com>
Date: Fri, 19 Dec 2025 18:20:52 -0800
Subject: [PATCH] [LLVM][ADT] Make `scope-exit` CTAD-capable
---
llvm/include/llvm/ADT/ScopeExit.h | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/llvm/include/llvm/ADT/ScopeExit.h b/llvm/include/llvm/ADT/ScopeExit.h
index 2f13fb65d34d8..04b602a69f7e3 100644
--- a/llvm/include/llvm/ADT/ScopeExit.h
+++ b/llvm/include/llvm/ADT/ScopeExit.h
@@ -15,13 +15,9 @@
#ifndef LLVM_ADT_SCOPEEXIT_H
#define LLVM_ADT_SCOPEEXIT_H
-#include "llvm/Support/Compiler.h"
-
-#include <type_traits>
#include <utility>
namespace llvm {
-namespace detail {
template <typename Callable> class scope_exit {
Callable ExitFunction;
@@ -47,17 +43,15 @@ template <typename Callable> class scope_exit {
}
};
-} // end namespace detail
+template <typename Callable> scope_exit(Callable) -> scope_exit<Callable>;
// Keeps the callable object that is passed in, and execute it at the
// destruction of the returned object (usually at the scope exit where the
// returned object is kept).
//
// Interface is specified by p0052r2.
-template <typename Callable>
-[[nodiscard]] detail::scope_exit<std::decay_t<Callable>>
-make_scope_exit(Callable &&F) {
- return detail::scope_exit<std::decay_t<Callable>>(std::forward<Callable>(F));
+template <typename Callable> [[nodiscard]] auto make_scope_exit(Callable &&F) {
+ return scope_exit(std::forward<Callable>(F));
}
} // end namespace llvm
More information about the llvm-commits
mailing list