Skip to content

Conversation

kazutakahirata
Copy link
Contributor

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Sep 6, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/157228.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/STLExtras.h (+4-12)
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index b23188cbdadeb..a5c45a21a2401 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -133,15 +133,6 @@ using is_one_of = std::disjunction<std::is_same<T, Ts>...>;
 template <typename T, typename... Ts>
 using are_base_of = std::conjunction<std::is_base_of<T, Ts>...>;
 
-namespace detail {
-template <typename T, typename... Us> struct TypesAreDistinct;
-template <typename T, typename... Us>
-struct TypesAreDistinct
-    : std::integral_constant<bool, !is_one_of<T, Us...>::value &&
-                                       TypesAreDistinct<Us...>::value> {};
-template <typename T> struct TypesAreDistinct<T> : std::true_type {};
-} // namespace detail
-
 /// Determine if all types in Ts are distinct.
 ///
 /// 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 {};
 /// asserted once per instantiation of a type which requires it.
 template <typename... Ts> struct TypesAreDistinct;
 template <> struct TypesAreDistinct<> : std::true_type {};
-template <typename... Ts>
-struct TypesAreDistinct
-    : std::integral_constant<bool, detail::TypesAreDistinct<Ts...>::value> {};
+template <typename T, typename... Us>
+struct TypesAreDistinct<T, Us...>
+    : std::conjunction<std::negation<is_one_of<T, Us...>>,
+                       TypesAreDistinct<Us...>> {};
 
 /// Find the first index where a type appears in a list of types.
 ///

@kazutakahirata kazutakahirata merged commit 0af4c7f into llvm:main Sep 6, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250905_ADT_STLExtras_TypesAreDistinct branch September 6, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants