nalgebra
nalgebra copied to clipboard
`U1, U2, ...` are usable as types but not as parameters
They are defined as type Uxyz = Const::<xyz>;
When you need to pass it as a generic parameter this works.
But there are some functions (reshape_generic
for example) that take Const::<N>, Const::<M>
in their function arguments, as a way to avoid the turbofish, as rust can deduce the type arguments from the function arguments.
However in this position we can't use U1, U2, ...
You get an error
error[E0423]: expected value, found type alias `na::U12`
Can we have const
s with the same name so Uxyz
can be used as a value as well?
Doesn't this solve the problem in concern https://github.com/dimforge/nalgebra/blob/dev/src/base/dimension.rs#L281 ?
This is something that's been bothering me too. The question is if introducing these constants can break any code - I don't think so, because the type aliases and the constant reside in type/value space respectively. I think it would be great to try this out with a PR.
Doesn't this solve the problem in concern https://github.com/dimforge/nalgebra/blob/dev/src/base/dimension.rs#L281 ?
The problem is that you can't write e.g
matrix.reshape_generic((0, 0), (U3, U1));
because U3
and U1
are type aliases. Currently you have to write U3::name()
or Const<3>
instead, both of which are more verbose. Introducing constants with the same name should hopefully allow the above example to compile.
One advantage i noticed Const::<>
has is that you can put a _
in the turbo fish and the compiler can often deduce the matrix size for you
If you enable the unstable feature, but still
As investigated in https://github.com/dimforge/nalgebra/pull/1111, adding the constants could be expensive to compile and may not match the implemented ToTypenum specializations.