Created on 2013-10-04.00:00:00 last changed 49 months ago
Rationale:
std::array like this seems like an "XY problem". The goal should be "replace C arrays" not "replace C arrays with std::array", because std::array is not suitable here. There are superior solutions being proposed, and will be available in a future version of C++ (e.g. using mdspan as a multi-dimensional view on an array).[ 2020-11-09 Status changed: Tentatively NAD → NAD. ]
[ 2020-02-14, Prague ]
LWG discussions and decision for NAD.
In order to replace some uses of C arrays with std::array, we need it to be possible to cast from a std::array<> to an equivalent C array. Core wording doesn't appear to be in quite the right state to allow casting, but if we specify that appropriate types are layout-compatible, we can at least write:
union { array<array<array<int, 2>, 3>, 4> arr; int carr[4][3][2]; };
to view memory as the other type: C++14 CD [class.mem]p18.
I believe it's sufficient to add "array<T, N> shall be layout-compatible ([basic.types]) with T[N]." to [array.overview], but we might also need some extension to [class.mem] to address the possibility of layout-compatibility between struct and array types.I checked that libc++ on MacOS already implements this, although it would be good for someone else to double-check; I haven't checked any other standard libraries.
History | |||
---|---|---|---|
Date | User | Action | Args |
2020-11-09 20:22:58 | admin | set | messages: + msg11533 |
2020-02-16 07:31:32 | admin | set | messages: + msg11133 |
2020-02-16 07:31:32 | admin | set | messages: + msg11132 |
2020-02-16 07:31:32 | admin | set | status: new -> nad |
2013-10-04 00:00:00 | admin | create |