1 // Structured binding in C++ can bind identifiers to subobjects of an object.
3 // There are three cases we need to test:
5 // 2) tuples like objects
6 // 3) non-static data members
8 // They can also bind by copy, reference or rvalue reference.
17 // We want to cover a mix of types and also different sizes to make sure we
18 // hande the offsets correctly.
19 struct MixedTypesAndSizesStruct
{
29 MixedTypesAndSizesStruct b
{{20, 30}, 'a', 'b', 50, 60, 'c'};
31 auto [a1
, b1
, c1
, d1
, e1
, f1
] = b
;
32 auto &[a2
, b2
, c2
, d2
, e2
, f2
] = b
;
33 auto &&[a3
, b3
, c3
, d3
, e3
, f3
] =
34 MixedTypesAndSizesStruct
{{20, 30}, 'a', 'b', 50, 60, 'c'};
36 // Array with different sized types
37 char carr
[]{'a', 'b', 'c'};
38 short sarr
[]{11, 12, 13};
39 int iarr
[]{22, 33, 44};
41 auto [carr_copy1
, carr_copy2
, carr_copy3
] = carr
;
42 auto [sarr_copy1
, sarr_copy2
, sarr_copy3
] = sarr
;
43 auto [iarr_copy1
, iarr_copy2
, iarr_copy3
] = iarr
;
45 auto &[carr_ref1
, carr_ref2
, carr_ref3
] = carr
;
46 auto &[sarr_ref1
, sarr_ref2
, sarr_ref3
] = sarr
;
47 auto &[iarr_ref1
, iarr_ref2
, iarr_ref3
] = iarr
;
49 auto &&[carr_rref1
, carr_rref2
, carr_rref3
] = carr
;
50 auto &&[sarr_rref1
, sarr_rref2
, sarr_rref3
] = sarr
;
51 auto &&[iarr_rref1
, iarr_rref2
, iarr_rref3
] = iarr
;
57 std::tuple
<float, char, int> tpl(x
, y
, z
);
58 auto [tx1
, ty1
, tz1
] = tpl
;
59 auto &[tx2
, ty2
, tz2
] = tpl
;
61 return a1
.x
+ b1
+ c1
+ d1
+ e1
+ f1
+ a2
.y
+ b2
+ c2
+ d2
+ e2
+ f2
+ a3
.x
+
62 b3
+ c3
+ d3
+ e3
+ f3
+ carr_copy1
+ carr_copy2
+ carr_copy3
+
63 sarr_copy1
+ sarr_copy2
+ sarr_copy3
+ iarr_copy1
+ iarr_copy2
+
64 iarr_copy3
+ carr_ref1
+ carr_ref2
+ carr_ref3
+ sarr_ref1
+
65 sarr_ref2
+ sarr_ref3
+ iarr_ref1
+ iarr_ref2
+ iarr_ref3
+
66 carr_rref1
+ carr_rref2
+ carr_rref3
+ sarr_rref1
+ sarr_rref2
+
67 sarr_rref3
+ iarr_rref1
+ iarr_rref2
+ iarr_rref3
+ tx1
+ ty1
+ tz1
+
68 tx2
+ ty2
+ tz2
; // break here