In some algorithm, we may want to index a single vector twice (e.g., bubble-sort)
for i in 0..vec.len() {
for j in 0..i {
if vec[i]>vec[j] {
vec.swap(i,j)
}
}
}
is it possible to provide some api that could index the same vector twice or even more?
// yields [&slice[i],&slice[j],&slice[k],...] where i<j<k<...
fn iter_ascend<T,const N:usize>(&[T])->impl Iterator<Item=[&T;N]> {...}
fn iter_ascend_mut<T,const N:usize>(&mut [T])->impl Iterator<Item=[&mut T;N]> {...}
// yields [&slice[i],&slice[j],&slice[k],...] where i>j>k>...
fn iter_descend<T,const N:usize>(&[T])->impl Iterator<Item=[&T;N]> {...}
fn iter_descend_mut<T,const N:usize>(&mut [T])->impl Iterator<Item=[&mut T;N]> {...}
// yields [&slice[i],&slice[j],&slice[k],...] for all valid i,j,k,...
fn iter<T,const N:usize>(&[T])->impl Iterator<Item=[&T;N]> {...}
// iter_mut is not possible to make such modification here.
Is it worth to wrote such a crate or just open an RFC?