Hi all
I am trying to generalize nested loops construction via generics with const parameters.
#![feature(generic_const_exprs)]
#[inline(always)]
fn iter_dim<F, const N: usize, const XI: usize>(x: &[i64; N], v: &mut [i64; N], f: &mut F)
where
F: FnMut(&[i64; N]),
[(); XI + 1]:,
{
if XI >= N {
return f(v);
}
for i in x[XI] - 1..x[XI] + 2 {
v[XI] = i;
iter_dim::<_, N, { XI + 1 }>(x, v, f)
}
}
fn main() {
let x: [i64; 3] = [1, 2, 3];
let mut i: [i64; 3] = [0, 0, 0];
iter_dim::<_, 3, 0>(&x, &mut i, &mut |i| println!("{:?}", i));
}
However, I receive only following errors using latest nightly compiler:
error: unconstrained generic constant
--> src/main.rs:217:44
|
217 | iter_dim::<_, N, { XI + 1 }>(x, v, f)
| ---------------------------- ^
| |
| required by a bound introduced by this call
|
= help: try adding a `where` bound using this expression: `where [(); XI + 1]:`
note: required by a bound in `iter_dim`
--> src/main.rs:209:10
|
206 | fn iter_dim<F, const N: usize, const XI: usize>(x: &[i64; N], v: &mut [i64; N], f: &mut F)
| -------- required by a bound in this function
...
209 | [(); XI + 1]:,
| ^^^^^^ required by this bound in `iter_dim`
Any help?