Skip to content

Commit 648831b

Browse files
[ADT] Move llvm::is_detected to STLForwardCompat.h (#158004)
llvm::is_detected forward-ported from C++20. As such, it belongs to STLForwardCompat.h.
1 parent 38b948b commit 648831b

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,6 @@ template <typename T> struct make_const_ref {
5858
using type = std::add_lvalue_reference_t<std::add_const_t<T>>;
5959
};
6060

61-
namespace detail {
62-
template <class, template <class...> class Op, class... Args> struct detector {
63-
using value_t = std::false_type;
64-
};
65-
template <template <class...> class Op, class... Args>
66-
struct detector<std::void_t<Op<Args...>>, Op, Args...> {
67-
using value_t = std::true_type;
68-
};
69-
} // end namespace detail
70-
71-
/// Detects if a given trait holds for some set of arguments 'Args'.
72-
/// For example, the given trait could be used to detect if a given type
73-
/// has a copy assignment operator:
74-
/// template<class T>
75-
/// using has_copy_assign_t = decltype(std::declval<T&>()
76-
/// = std::declval<const T&>());
77-
/// bool fooHasCopyAssign = is_detected<has_copy_assign_t, FooClass>::value;
78-
template <template <class...> class Op, class... Args>
79-
using is_detected = typename detail::detector<void, Op, Args...>::value_t;
80-
8161
/// This class provides various trait information about a callable object.
8262
/// * To access the number of arguments: Traits::num_args
8363
/// * To access the type of an argument: Traits::arg_t<Index>

llvm/include/llvm/ADT/STLForwardCompat.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ template <typename T>
4949
using type_identity_t // NOLINT(readability-identifier-naming)
5050
= typename llvm::type_identity<T>::type;
5151

52+
namespace detail {
53+
template <class, template <class...> class Op, class... Args> struct detector {
54+
using value_t = std::false_type;
55+
};
56+
template <template <class...> class Op, class... Args>
57+
struct detector<std::void_t<Op<Args...>>, Op, Args...> {
58+
using value_t = std::true_type;
59+
};
60+
} // end namespace detail
61+
62+
/// Detects if a given trait holds for some set of arguments 'Args'.
63+
/// For example, the given trait could be used to detect if a given type
64+
/// has a copy assignment operator:
65+
/// template<class T>
66+
/// using has_copy_assign_t = decltype(std::declval<T&>()
67+
/// = std::declval<const T&>());
68+
/// bool fooHasCopyAssign = is_detected<has_copy_assign_t, FooClass>::value;
69+
template <template <class...> class Op, class... Args>
70+
using is_detected = typename detail::detector<void, Op, Args...>::value_t;
71+
5272
//===----------------------------------------------------------------------===//
5373
// Features from C++23
5474
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)