Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update iter::order to be more generic. #22887

Merged
merged 1 commit into from
Feb 28, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 20 additions & 34 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2874,10 +2874,10 @@ pub mod order {
use super::Iterator;

/// Compare `a` and `b` for equality using `Eq`
pub fn equals<A, T, S>(mut a: T, mut b: S) -> bool where
pub fn equals<A, L, R>(mut a: L, mut b: R) -> bool where
A: Eq,
T: Iterator<Item=A>,
S: Iterator<Item=A>,
L: Iterator<Item=A>,
R: Iterator<Item=A>,
{
loop {
match (a.next(), b.next()) {
Expand All @@ -2889,10 +2889,10 @@ pub mod order {
}

/// Order `a` and `b` lexicographically using `Ord`
pub fn cmp<A, T, S>(mut a: T, mut b: S) -> cmp::Ordering where
pub fn cmp<A, L, R>(mut a: L, mut b: R) -> cmp::Ordering where
A: Ord,
T: Iterator<Item=A>,
S: Iterator<Item=A>,
L: Iterator<Item=A>,
R: Iterator<Item=A>,
{
loop {
match (a.next(), b.next()) {
Expand All @@ -2908,10 +2908,8 @@ pub mod order {
}

/// Order `a` and `b` lexicographically using `PartialOrd`
pub fn partial_cmp<A, T, S>(mut a: T, mut b: S) -> Option<cmp::Ordering> where
A: PartialOrd,
T: Iterator<Item=A>,
S: Iterator<Item=A>,
pub fn partial_cmp<L: Iterator, R: Iterator>(mut a: L, mut b: R) -> Option<cmp::Ordering> where
L::Item: PartialOrd<R::Item>
{
loop {
match (a.next(), b.next()) {
Expand All @@ -2927,10 +2925,8 @@ pub mod order {
}

/// Compare `a` and `b` for equality (Using partial equality, `PartialEq`)
pub fn eq<A, B, L, R>(mut a: L, mut b: R) -> bool where
A: PartialEq<B>,
L: Iterator<Item=A>,
R: Iterator<Item=B>,
pub fn eq<L: Iterator, R: Iterator>(mut a: L, mut b: R) -> bool where
L::Item: PartialEq<R::Item>,
{
loop {
match (a.next(), b.next()) {
Expand All @@ -2942,10 +2938,8 @@ pub mod order {
}

/// Compare `a` and `b` for nonequality (Using partial equality, `PartialEq`)
pub fn ne<A, B, L, R>(mut a: L, mut b: R) -> bool where
A: PartialEq<B>,
L: Iterator<Item=A>,
R: Iterator<Item=B>,
pub fn ne<L: Iterator, R: Iterator>(mut a: L, mut b: R) -> bool where
L::Item: PartialEq<R::Item>,
{
loop {
match (a.next(), b.next()) {
Expand All @@ -2957,10 +2951,8 @@ pub mod order {
}

/// Return `a` < `b` lexicographically (Using partial order, `PartialOrd`)
pub fn lt<A, T, S>(mut a: T, mut b: S) -> bool where
A: PartialOrd,
T: Iterator<Item=A>,
S: Iterator<Item=A>,
pub fn lt<R: Iterator, L: Iterator>(mut a: L, mut b: R) -> bool where
L::Item: PartialOrd<R::Item>,
{
loop {
match (a.next(), b.next()) {
Expand All @@ -2973,10 +2965,8 @@ pub mod order {
}

/// Return `a` <= `b` lexicographically (Using partial order, `PartialOrd`)
pub fn le<A, T, S>(mut a: T, mut b: S) -> bool where
A: PartialOrd,
T: Iterator<Item=A>,
S: Iterator<Item=A>,
pub fn le<L: Iterator, R: Iterator>(mut a: L, mut b: R) -> bool where
L::Item: PartialOrd<R::Item>,
{
loop {
match (a.next(), b.next()) {
Expand All @@ -2989,10 +2979,8 @@ pub mod order {
}

/// Return `a` > `b` lexicographically (Using partial order, `PartialOrd`)
pub fn gt<A, T, S>(mut a: T, mut b: S) -> bool where
A: PartialOrd,
T: Iterator<Item=A>,
S: Iterator<Item=A>,
pub fn gt<L: Iterator, R: Iterator>(mut a: L, mut b: R) -> bool where
L::Item: PartialOrd<R::Item>,
{
loop {
match (a.next(), b.next()) {
Expand All @@ -3005,10 +2993,8 @@ pub mod order {
}

/// Return `a` >= `b` lexicographically (Using partial order, `PartialOrd`)
pub fn ge<A, T, S>(mut a: T, mut b: S) -> bool where
A: PartialOrd,
T: Iterator<Item=A>,
S: Iterator<Item=A>,
pub fn ge<L: Iterator, R: Iterator>(mut a: L, mut b: R) -> bool where
L::Item: PartialOrd<R::Item>,
{
loop {
match (a.next(), b.next()) {
Expand Down