[llvm] [ADT] Simplify enable_if_struct_deref_supported (NFC) (PR #159939)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 20 11:19:35 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/159939

This patch simplifies enable_if_struct_deref_supported by using a
default template parameter as a temporary type alias.  This way, we do
not have to repeat decltype(...).


>From 3a37da1799bc19ee7ec6c0396e35218c3d00766f Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 19 Sep 2025 18:58:37 -0700
Subject: [PATCH] [ADT] Simplify enable_if_struct_deref_supported (NFC)

This patch simplifies enable_if_struct_deref_supported by using a
default template parameter as a temporary type alias.  This way, we do
not have to repeat decltype(...).
---
 llvm/include/llvm/ADT/fallible_iterator.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/ADT/fallible_iterator.h b/llvm/include/llvm/ADT/fallible_iterator.h
index b42f62b67fd66..76fa054f2eb94 100644
--- a/llvm/include/llvm/ADT/fallible_iterator.h
+++ b/llvm/include/llvm/ADT/fallible_iterator.h
@@ -67,10 +67,9 @@ namespace llvm {
 /// without requiring redundant error checks.
 template <typename Underlying> class fallible_iterator {
 private:
-  template <typename T>
-  using enable_if_struct_deref_supported = std::enable_if_t<
-      !std::is_void<decltype(std::declval<T>().operator->())>::value,
-      decltype(std::declval<T>().operator->())>;
+  template <typename T, typename U = decltype(std::declval<T>().operator->())>
+  using enable_if_struct_deref_supported =
+      std::enable_if_t<!std::is_void_v<U>, U>;
 
 public:
   /// Construct a fallible iterator that *cannot* be used as an end-of-range



More information about the llvm-commits mailing list