-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Default for all array sizes #88744
Comments
There's an open issue for this... somewhere, I can't find it. |
I've updated the Godbolt link to include creation of arrays of length 0 for both ZST and not ZST. It doesn't look like there is any difference as |
The issue is that |
There's some discussion in #74060 (comment) and the references from there. |
Ok, I see the point. It lead me to the question now posted in zullip, may be it would be a nice feature that may go along and parallel with specialization (and potentially much easier to implement) |
SummaryBefore we had const-generics we had some macros manually implementing Default for a few different array sizes, and we were too clever and special-cased
This all happened about 2 years ago, and there is currently no clear roadmap to resolving the issue either way. History
|
@hellow554 I think #61415 is the correct issue. @Gankra hey, it's nice summary. could you update to include a pointer to the issue? @shamatar also, now it's directed to the correct issue. this one can be closed, maybe? |
Yes, I'll close this in favor of #61415. |
I've made a simple Godbolt for a demonstration of the approach.
In short, with array::map stabilized in 1.55 it's now possible to make an array
[T; N]
of default values ofT
by invoking[(); N].map(|_| T::default())
. There is no difference in the emitted assembly for either O2 or O3 optimization levels in my short example forusize
and user defined type (both ZST and not ZST), but obviously there is no guarantee that some more complex cases would not diverge.I would expect that lifting a hard limitation of 32 on the size of the array would be handy in general.
The text was updated successfully, but these errors were encountered: