[clang] [clang-tools-extra] [llvm] [Clang] Add __builtin_type_pack_dedup template to deduplicate types in template arguments (PR #106730)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 18 11:37:05 PDT 2024


================
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __type_list_dedup BuiltinTemplateDecl.
+  BTK__type_list_dedup,
----------------
mizvekov wrote:

An advantage of the builtin templates is that we can introduce deduction rules for them, although we currently don't do that for any of the existing ones.

One example:
```C++
template <class...> struct A {};
template <class T, class U> void f(__builtin_type_pack_dedup<A, T, U>);

void test() {
  A<int, int, char> a;
  f(a); // OK, deduced as T = int, U = char
}
```

An example of how this could apply to existing __make_integer_seq:
```C++
template <class T, T Count> void f(__make_integer_seq(std::integer_sequence, T, Count)) {}

void test() {
  f(std::make_integer_sequence<int, 12>{}); // OK, deduced T = int, Count = 12
}
```
```

https://github.com/llvm/llvm-project/pull/106730


More information about the cfe-commits mailing list