[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 2 21:51:44 PST 2025
================
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify
+// expected-no-diagnostics
+
+template <typename T>
+struct type_ { };
+
+template <typename ...T>
+auto sum(T... t) { return (t + ...); }
+
+struct my_struct {
+ int a;
+ int b;
+ int c;
+ int d;
+};
+
+struct fake_tuple {
+ int arr[4] = {1, 2, 3, 6};
+
+ template <unsigned i>
+ int get() {
+ return arr[i];
+ }
+};
+
+namespace std {
+ template <typename T>
+ struct tuple_size;
+ template <unsigned i, typename T>
+ struct tuple_element;
+
+ template <>
+ struct tuple_size<fake_tuple> {
+ static constexpr unsigned value = 4;
+ };
+
+ template <unsigned i>
+ struct tuple_element<i, fake_tuple> {
+ using type = int;
+ };
+}
+
+
+template <typename T>
+void decompose_tuple() {
+ auto tup = T{{1, 2, 3, 6}};
+ auto&& [x, ...rest, y] = tup;
+
+ ((void)type_<int>(type_<decltype(rest)>{}), ...);
+
+ T arrtup[2] = {T{{1, 2, 3, 6}},
+ T{{7, 9, 10, 11}}};
+ int sum = 0;
+ for (auto [...xs] : arrtup) {
+ sum += (xs + ...);
+ }
+}
+
+template <typename T>
+void decompose_struct() {
+ T obj{1, 2, 3, 6};
+ auto [x, ...rest, y] = obj;
+}
+
+template <typename T>
+void decompose_array() {
+ // previously unable to use non-dependent array here
+ // Fixes https://bugs.llvm.org/show_bug.cgi?id=45964
----------------
zyn0217 wrote:
Oh sorry I missed that
So if it directly links to code that comes next, feel free to preserve it; otherwise it looks misleading
https://github.com/llvm/llvm-project/pull/121417
More information about the cfe-commits
mailing list