std: Implement RandomAccessIterator for Invert
This commit is contained in:
parent
c5e4c55989
commit
872d15d464
@ -106,6 +106,16 @@ impl<A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Invert<T> {
|
||||
fn next_back(&mut self) -> Option<A> { self.iter.next() }
|
||||
}
|
||||
|
||||
impl<A, T: DoubleEndedIterator<A> + RandomAccessIterator<A>> RandomAccessIterator<A>
|
||||
for Invert<T> {
|
||||
#[inline]
|
||||
fn indexable(&self) -> uint { self.iter.indexable() }
|
||||
#[inline]
|
||||
fn idx(&self, index: uint) -> Option<A> {
|
||||
self.iter.idx(self.indexable() - index - 1)
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator adaptors provided for every `Iterator` implementation. The adaptor objects are also
|
||||
/// implementations of the `Iterator` trait.
|
||||
///
|
||||
@ -2017,6 +2027,17 @@ mod tests {
|
||||
check_randacc_iter(xs.iter().enumerate(), xs.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_random_access_invert() {
|
||||
let xs = [1, 2, 3, 4, 5];
|
||||
check_randacc_iter(xs.iter().invert(), xs.len());
|
||||
let mut it = xs.iter().invert();
|
||||
it.next();
|
||||
it.next_back();
|
||||
it.next();
|
||||
check_randacc_iter(it, xs.len() - 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_random_access_zip() {
|
||||
let xs = [1, 2, 3, 4, 5];
|
||||
|
Loading…
x
Reference in New Issue
Block a user