Rollup merge of #22887 - JP-Ellis:master, r=huonw

Updated the function to allow comparisons between different types since PartialOrd and PartialEq allow this.
This commit is contained in:
Manish Goregaokar 2015-02-28 13:57:08 +05:30
commit 6b1471967c

View File

@ -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()) {
@ -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()) {
@ -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()) {
@ -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()) {
@ -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()) {
@ -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()) {
@ -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()) {
@ -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()) {
@ -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()) {