use std::cmp;
#[derive(Clone)]
pub struct Zip<T> {
t: T
}
impl<T> Zip<T> where Zip<T>: Iterator
{
pub fn new(t: T) -> Zip<T>
{
Zip{t: t}
}
}
macro_rules! impl_zip_iter(
($($B:ident),*) => (
#[allow(non_snake_case)]
impl<$($B),*> Iterator for Zip<($($B,)*)>
where
$(
$B: Iterator,
)*
{
type Item = ($(<$B as Iterator>::Item,)*);
fn next(&mut self) -> Option<
($(<$B as Iterator>::Item,)*)
>
{
let &mut Zip { t : ($(ref mut $B,)*)} = self;
$(
let $B = match $B.next() {
None => return None,
Some(elt) => elt
};
)*
Some(($($B,)*))
}
fn size_hint(&self) -> (usize, Option<usize>)
{
let low = ::std::usize::MAX;
let high = None;
let &Zip { t : ($(ref $B,)*) } = self;
$(
let (l, h) = $B.size_hint();
let low = cmp::min(low, l);
let high = match (high, h) {
(Some(u1), Some(u2)) => Some(cmp::min(u1, u2)),
_ => high.or(h)
};
)*
(low, high)
}
}
);
);
impl_zip_iter!(A);
impl_zip_iter!(A, B);
impl_zip_iter!(A, B, C);
impl_zip_iter!(A, B, C, D);
impl_zip_iter!(A, B, C, D, E);
impl_zip_iter!(A, B, C, D, E, F);
impl_zip_iter!(A, B, C, D, E, F, G);
impl_zip_iter!(A, B, C, D, E, F, G, H);
impl_zip_iter!(A, B, C, D, E, F, G, H, I);