Make std::array::from_fn
a const fn
#178
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Proposal
Problem statement
I want to create a repeated array of a non-copiable, non-cloneable type in a generic
const
context, and I want to be able to convert one array to another within it.Motivation, use-cases
I've got constants like this:
Also, certain lookup tables where the mapping is less trivial come to mind, like the one used for optimized CRC32 implementations.
In non-
const
contexts, the above explicitly written tables could be easily simplified to the following, and wouldn't even need the comments to explain their intent:The CRC32 table could be simplified to just the following:
Solution sketches
Title says it all. Making
std::array::from_fn
aconst fn
would allow the simplified versions to just be used for initializingstatic
variables.Links and related work
Obviously https://doc.rust-lang.org/std/array/fn.from_fn.html is prior art. Also, this has been requested in rust-lang/rust#89379, though I didn't find that until after writing this up.
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: