z
Size: a a a
AB
AB
G
AB
SE
However, the original version of to_array only takes an lvalue reference-to-array, and users reported[2] some issues regarding this design. The first issue is that it becomes very hackish to deduce only the array bound from a braced-init-list:
auto x = to_array<int const>({ 2, 4 }); // array<int, 2>
The language treats braced-init-list as a prvalue of an array type when deducing against reference-to-array. The code above adds const to coin a reference that can bind to such a prvalue, and leaves the const to be stripped later. Anyhow, the code isn’t doing what it says.
The second issue is that it does not support move-only elements, such as unique_ptr, no matter how you hack.
So we should add the rvalue-reference overload to fill this hole regarding type system.
AB
G
AB
G
G
test.c:105:22: error: expected identifier or ‘(’ before ‘_Generic’
105 | #define WRITE_INT(T) _Generic( (T), \
| ^~~~~~~~
test.c:116:1: note: in expansion of macro ‘WRITE_INT’
116 | WRITE_INT(int16_t)
| ^~~~~~~~~
AB
test.c:105:22: error: expected identifier or ‘(’ before ‘_Generic’
105 | #define WRITE_INT(T) _Generic( (T), \
| ^~~~~~~~
test.c:116:1: note: in expansion of macro ‘WRITE_INT’
116 | WRITE_INT(int16_t)
| ^~~~~~~~~
G
G
AB
AB
G
AB
G