4 ms·
Is that different from something like this? fn main() { let list = &[0, 1, 2, 3, 4, 5, 6, 7, 8]; let i = 0; let j = 4; let k = 8;
by arcticbull 8y ago
Is that different from something like this?
fn main() {
let list = &[0, 1, 2, 3, 4, 5, 6, 7, 8];
let i = 0;
let j = 4;
let k = 8;
let iter_ij = list[i ..= j].iter();
let iter_jk = list[j ..= k].iter();
let pairs = Iterator::zip(iter_ij, iter_jk);
for (a, b) in pairs {
println!("{}, {}", a, b);
}
}
- klodolph 8y agoYes, that is different, because in C++ you can move j forward and backwards.
- arcticbull 8y agoAhh, I see, thanks for clarifying. Rust's Iterators are similar to C++ ForwardIterators. It seems C++'s default is BidirectionalIterator.
- klodolph 8y agoEven C++ ForwardIterators are more powerful, because you can move them independently. Rust lets you move the beginning of the range forwards, and maybe the end of the range backwards. With ForwardIterator you would be able to move the end of the range forwards, making the range longer.