On 11/21/13 9:37 PM, Tommi wrote:
In the following example, I have a function which takes an
input-iterator to ints. It would be a loss of generality for that
function to require its iterator argument to return its elements by
pointer, because generator iterators like range(x, y) or random number
generators etc. generally must return their elements by value. This
makes it inconvenient to pass a vector iterator for example since it
returns its elements by pointer. I wouldn't like to be writing
values.iter().map(|a| *a) nor accept the performance hit it entails.
I think it's unlikely that the performance hit there would be
significant. Actually, the example you gave, there won't be any at all
because it'll be devirtualized and inlined.
I'd
rather write something like values.value_iter().
fn print_these<T: Iterator<int>>(mut it: T) {
for i in it {
println!("{}", i);
}
}
fn main() {
let mut values = range(0, 3);
print_these(values);
let mut values = [3, 4, 5];
print_these(values.iter().map(|a| *a));
}
There is `move_iter`, but that only works for owned vectors. Perhaps
what you want is a kind of iterator that clones its values...
Patrick
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev