[llvm] [llvm][NFC] Simplify implementation of `isa` (PR #161403)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 10:00:47 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Victor Chernyakin (localspook)
<details>
<summary>Changes</summary>
Using a fold instead of template recursion.
---
Full diff: https://github.com/llvm/llvm-project/pull/161403.diff
1 Files Affected:
- (modified) llvm/include/llvm/Support/Casting.h (+2-7)
``````````diff
diff --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index 66fdcb44ea2c0..2a9a149327d83 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -544,14 +544,9 @@ struct CastInfo<To, std::optional<From>> : public OptionalValueCast<To, From> {
///
/// if (isa<Type>(myVal)) { ... }
/// if (isa<Type0, Type1, Type2>(myVal)) { ... }
-template <typename To, typename From>
-[[nodiscard]] inline bool isa(const From &Val) {
- return CastInfo<To, const From>::isPossible(Val);
-}
-
-template <typename First, typename Second, typename... Rest, typename From>
+template <typename... To, typename From>
[[nodiscard]] inline bool isa(const From &Val) {
- return isa<First>(Val) || isa<Second, Rest...>(Val);
+ return (CastInfo<To, const From>::isPossible(Val) || ...);
}
/// cast<X> - Return the argument parameter cast to the specified type. This
``````````
</details>
https://github.com/llvm/llvm-project/pull/161403
More information about the llvm-commits
mailing list