I'm trying to generalize some algebraic operations in Rust (like for groups, rings, fields, etc), and I ran into this problem trying to implement the cross product of two "sets" (Vec's).
(Note that this is using const_generics in the nightly toolchain.)
fn CrossProduct<T, const N: usize, const M: usize>(lhs: Vec<[T;N]>, rhs: Vec<[T;M]>) -> Vec<[T;N+M]> {
let mut out: Vec<[T;N+M]> = Vec::with_capacity(lhs.len() * rhs.len());
for i in 0..lhs.len() {
for j in 0..rhs.len() {
let mut inner: [T; N+M] = [lhs[i][0]; N+M];
for idx in 1..N {
inner[idx] = lhs[i][idx];
}
for idx in 0..M {
inner[idx + N] = rhs[j][idx];
}
out.push(inner);
}
}
out
}
Wherever I have the expression [T;N+M], I get an error that says constant expression depends on a generic parameter, which makes no sense.