[llvm] [ADT] Move llvm::is_detected to STLForwardCompat.h (PR #158004)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 00:13:09 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/158004
llvm::is_detected forward-ported from C++20. As such, it belongs to
STLForwardCompat.h.
>From d6d9b52ec5c63f16d9beab51060e0711de982f13 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 8 Sep 2025 00:51:42 -0700
Subject: [PATCH] [ADT] Move llvm::is_detected to STLForwardCompat.h
llvm::is_detected forward-ported from C++20. As such, it belongs to
STLForwardCompat.h.
---
llvm/include/llvm/ADT/STLExtras.h | 20 --------------------
llvm/include/llvm/ADT/STLForwardCompat.h | 20 ++++++++++++++++++++
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 5923fdd46a378..099bef288b953 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -58,26 +58,6 @@ template <typename T> struct make_const_ref {
using type = std::add_lvalue_reference_t<std::add_const_t<T>>;
};
-namespace detail {
-template <class, template <class...> class Op, class... Args> struct detector {
- using value_t = std::false_type;
-};
-template <template <class...> class Op, class... Args>
-struct detector<std::void_t<Op<Args...>>, Op, Args...> {
- using value_t = std::true_type;
-};
-} // end namespace detail
-
-/// Detects if a given trait holds for some set of arguments 'Args'.
-/// For example, the given trait could be used to detect if a given type
-/// has a copy assignment operator:
-/// template<class T>
-/// using has_copy_assign_t = decltype(std::declval<T&>()
-/// = std::declval<const T&>());
-/// bool fooHasCopyAssign = is_detected<has_copy_assign_t, FooClass>::value;
-template <template <class...> class Op, class... Args>
-using is_detected = typename detail::detector<void, Op, Args...>::value_t;
-
/// This class provides various trait information about a callable object.
/// * To access the number of arguments: Traits::num_args
/// * To access the type of an argument: Traits::arg_t<Index>
diff --git a/llvm/include/llvm/ADT/STLForwardCompat.h b/llvm/include/llvm/ADT/STLForwardCompat.h
index 0ef8cb5d02e50..da9d3ab0e32a3 100644
--- a/llvm/include/llvm/ADT/STLForwardCompat.h
+++ b/llvm/include/llvm/ADT/STLForwardCompat.h
@@ -49,6 +49,26 @@ template <typename T>
using type_identity_t // NOLINT(readability-identifier-naming)
= typename llvm::type_identity<T>::type;
+namespace detail {
+template <class, template <class...> class Op, class... Args> struct detector {
+ using value_t = std::false_type;
+};
+template <template <class...> class Op, class... Args>
+struct detector<std::void_t<Op<Args...>>, Op, Args...> {
+ using value_t = std::true_type;
+};
+} // end namespace detail
+
+/// Detects if a given trait holds for some set of arguments 'Args'.
+/// For example, the given trait could be used to detect if a given type
+/// has a copy assignment operator:
+/// template<class T>
+/// using has_copy_assign_t = decltype(std::declval<T&>()
+/// = std::declval<const T&>());
+/// bool fooHasCopyAssign = is_detected<has_copy_assign_t, FooClass>::value;
+template <template <class...> class Op, class... Args>
+using is_detected = typename detail::detector<void, Op, Args...>::value_t;
+
//===----------------------------------------------------------------------===//
// Features from C++23
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list