mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-23 22:14:15 +00:00
alloc: Implement rfold for VecDeque iterators
This commit is contained in:
parent
a59a25d8e6
commit
84c90f3022
@ -98,6 +98,7 @@
|
||||
#![feature(generic_param_attrs)]
|
||||
#![feature(i128_type)]
|
||||
#![feature(inclusive_range)]
|
||||
#![feature(iter_rfold)]
|
||||
#![feature(lang_items)]
|
||||
#![feature(needs_allocator)]
|
||||
#![feature(nonzero)]
|
||||
|
@ -1973,6 +1973,14 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
|
||||
self.head = wrap_index(self.head.wrapping_sub(1), self.ring.len());
|
||||
unsafe { Some(self.ring.get_unchecked(self.head)) }
|
||||
}
|
||||
|
||||
fn rfold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
|
||||
where F: FnMut(Acc, Self::Item) -> Acc
|
||||
{
|
||||
let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
|
||||
accum = back.iter().rfold(accum, &mut f);
|
||||
front.iter().rfold(accum, &mut f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -2058,6 +2066,14 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
|
||||
Some(&mut *(elem as *mut _))
|
||||
}
|
||||
}
|
||||
|
||||
fn rfold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
|
||||
where F: FnMut(Acc, Self::Item) -> Acc
|
||||
{
|
||||
let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
|
||||
accum = back.iter_mut().rfold(accum, &mut f);
|
||||
front.iter_mut().rfold(accum, &mut f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
Loading…
Reference in New Issue
Block a user