Index a tuple using a `const fn` value?


#1

The tuple-index syntax, using . like a member-access followed by a whole-number literal, does not permit using a const fn computed value:

Was this issue ever resolved, and/or is there a plan to resolve it?


#2

I wonder if you could do that using another const fn or a macro, but my mental-type-system screams at the very idea of doing that. Tuples are for cases where you want potentially different types to live together and the order is kind of not really important… (basically, structs but when I’m too lazy to think about names or declaring them), which makes indexing kind of not make sense in that context. Would it make sense to use fixed-size array instead?


#3

The numbers for indexing into tuples aren’t really “values” that can be output from a function, they are more like variable names such as what you would use to access a struct member. It is not surprising that the output of a function should be unusable here, const fn notwithstanding.

EDIT: Meant “unusable”, not “usable.”


#4

Yes, that makes sense.


#5

C++ does this with get<0>(x); rust will plausibly get something like that eventually. (But it’ll be much more annoying to use overall because of the lack of duck typing.)