Skip to content

Commit 0af4c7f

Browse files
[ADT] Simplify TypesAreDistinct with std::conjunction (NFC) (#157228)
This patch uses std::conjunction to succinctly compute "AND" of: - std::negation<is_one_of<T, Us...>> - TypesAreDistinct<Us...> // recursive step This way, we can eliminate the entire "detail" block.
1 parent 3eacaa3 commit 0af4c7f

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ using is_one_of = std::disjunction<std::is_same<T, Ts>...>;
133133
template <typename T, typename... Ts>
134134
using are_base_of = std::conjunction<std::is_base_of<T, Ts>...>;
135135

136-
namespace detail {
137-
template <typename T, typename... Us> struct TypesAreDistinct;
138-
template <typename T, typename... Us>
139-
struct TypesAreDistinct
140-
: std::integral_constant<bool, !is_one_of<T, Us...>::value &&
141-
TypesAreDistinct<Us...>::value> {};
142-
template <typename T> struct TypesAreDistinct<T> : std::true_type {};
143-
} // namespace detail
144-
145136
/// Determine if all types in Ts are distinct.
146137
///
147138
/// Useful to statically assert when Ts is intended to describe a non-multi set
@@ -151,9 +142,10 @@ template <typename T> struct TypesAreDistinct<T> : std::true_type {};
151142
/// asserted once per instantiation of a type which requires it.
152143
template <typename... Ts> struct TypesAreDistinct;
153144
template <> struct TypesAreDistinct<> : std::true_type {};
154-
template <typename... Ts>
155-
struct TypesAreDistinct
156-
: std::integral_constant<bool, detail::TypesAreDistinct<Ts...>::value> {};
145+
template <typename T, typename... Us>
146+
struct TypesAreDistinct<T, Us...>
147+
: std::conjunction<std::negation<is_one_of<T, Us...>>,
148+
TypesAreDistinct<Us...>> {};
157149

158150
/// Find the first index where a type appears in a list of types.
159151
///

0 commit comments

Comments
 (0)