2016-02-09 17:54:53 +00:00
|
|
|
// See src/libstd/primitive_docs.rs for documentation.
|
2013-05-28 21:35:52 +00:00
|
|
|
|
2019-04-15 02:23:21 +00:00
|
|
|
use crate::cmp::Ordering::*;
|
|
|
|
use crate::cmp::*;
|
2013-05-18 09:43:14 +00:00
|
|
|
|
2013-05-18 11:38:06 +00:00
|
|
|
// macro for implementing n-ary tuple functions and operations
|
2013-05-19 08:51:14 +00:00
|
|
|
macro_rules! tuple_impls {
|
2013-05-18 11:38:06 +00:00
|
|
|
($(
|
2014-02-16 09:25:28 +00:00
|
|
|
$Tuple:ident {
|
2015-03-15 17:15:38 +00:00
|
|
|
$(($idx:tt) -> $T:ident)+
|
2013-03-26 23:08:05 +00:00
|
|
|
}
|
2013-05-19 08:51:14 +00:00
|
|
|
)+) => {
|
2013-11-29 14:52:38 +00:00
|
|
|
$(
|
2015-01-24 05:48:20 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-07-01 23:41:39 +00:00
|
|
|
impl<$($T:PartialEq),+> PartialEq for ($($T,)+) where last_type!($($T,)+): ?Sized {
|
2013-11-29 14:52:38 +00:00
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &($($T,)+)) -> bool {
|
2016-11-12 19:20:58 +00:00
|
|
|
$(self.$idx == other.$idx)&&+
|
2013-11-29 14:52:38 +00:00
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &($($T,)+)) -> bool {
|
2016-11-12 19:20:58 +00:00
|
|
|
$(self.$idx != other.$idx)||+
|
2012-11-15 02:59:30 +00:00
|
|
|
}
|
2013-11-29 14:52:38 +00:00
|
|
|
}
|
2012-08-27 23:26:35 +00:00
|
|
|
|
2015-01-24 05:48:20 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-07-01 23:41:39 +00:00
|
|
|
impl<$($T:Eq),+> Eq for ($($T,)+) where last_type!($($T,)+): ?Sized {}
|
2013-05-19 08:51:14 +00:00
|
|
|
|
2015-01-24 05:48:20 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-07-01 23:41:39 +00:00
|
|
|
impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+)
|
|
|
|
where last_type!($($T,)+): ?Sized {
|
2014-06-18 06:25:51 +00:00
|
|
|
#[inline]
|
|
|
|
fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
|
2014-12-09 16:44:56 +00:00
|
|
|
lexical_partial_cmp!($(self.$idx, other.$idx),+)
|
2014-06-18 06:25:51 +00:00
|
|
|
}
|
2013-11-29 14:52:38 +00:00
|
|
|
#[inline]
|
|
|
|
fn lt(&self, other: &($($T,)+)) -> bool {
|
2014-12-09 16:44:56 +00:00
|
|
|
lexical_ord!(lt, $(self.$idx, other.$idx),+)
|
2013-11-29 14:52:38 +00:00
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn le(&self, other: &($($T,)+)) -> bool {
|
2014-12-09 16:44:56 +00:00
|
|
|
lexical_ord!(le, $(self.$idx, other.$idx),+)
|
2013-11-29 14:52:38 +00:00
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ge(&self, other: &($($T,)+)) -> bool {
|
2014-12-09 16:44:56 +00:00
|
|
|
lexical_ord!(ge, $(self.$idx, other.$idx),+)
|
2013-05-18 11:38:06 +00:00
|
|
|
}
|
2013-11-29 14:52:38 +00:00
|
|
|
#[inline]
|
|
|
|
fn gt(&self, other: &($($T,)+)) -> bool {
|
2014-12-09 16:44:56 +00:00
|
|
|
lexical_ord!(gt, $(self.$idx, other.$idx),+)
|
2013-11-29 14:52:38 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-19 08:51:14 +00:00
|
|
|
|
2015-01-24 05:48:20 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-07-01 23:41:39 +00:00
|
|
|
impl<$($T:Ord),+> Ord for ($($T,)+) where last_type!($($T,)+): ?Sized {
|
2013-11-29 14:52:38 +00:00
|
|
|
#[inline]
|
|
|
|
fn cmp(&self, other: &($($T,)+)) -> Ordering {
|
2014-12-09 16:44:56 +00:00
|
|
|
lexical_cmp!($(self.$idx, other.$idx),+)
|
2013-05-19 08:51:14 +00:00
|
|
|
}
|
2013-11-29 14:52:38 +00:00
|
|
|
}
|
2013-06-15 01:27:52 +00:00
|
|
|
|
2015-01-24 05:48:20 +00:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2013-11-29 14:52:38 +00:00
|
|
|
impl<$($T:Default),+> Default for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn default() -> ($($T,)+) {
|
|
|
|
($({ let x: $T = Default::default(); x},)+)
|
2013-09-12 04:49:25 +00:00
|
|
|
}
|
2013-11-29 14:52:38 +00:00
|
|
|
}
|
|
|
|
)+
|
2013-05-19 08:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 20:07:22 +00:00
|
|
|
// Constructs an expression that performs a lexical ordering using method $rel.
|
|
|
|
// The values are interleaved, so the macro invocation for
|
|
|
|
// `(a1, a2, a3) < (b1, b2, b3)` would be `lexical_ord!(lt, a1, b1, a2, b2,
|
2013-05-19 08:51:14 +00:00
|
|
|
// a3, b3)` (and similarly for `lexical_cmp`)
|
2013-08-08 20:07:22 +00:00
|
|
|
macro_rules! lexical_ord {
|
|
|
|
($rel: ident, $a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
2014-12-09 16:44:56 +00:00
|
|
|
if $a != $b { lexical_ord!($rel, $a, $b) }
|
2013-08-08 20:07:22 +00:00
|
|
|
else { lexical_ord!($rel, $($rest_a, $rest_b),+) }
|
2013-05-19 08:51:14 +00:00
|
|
|
};
|
2014-12-09 16:44:56 +00:00
|
|
|
($rel: ident, $a:expr, $b:expr) => { ($a) . $rel (& $b) };
|
2013-05-19 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
2014-06-18 06:25:51 +00:00
|
|
|
macro_rules! lexical_partial_cmp {
|
|
|
|
($a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
2014-12-09 16:44:56 +00:00
|
|
|
match ($a).partial_cmp(&$b) {
|
2014-06-18 06:25:51 +00:00
|
|
|
Some(Equal) => lexical_partial_cmp!($($rest_a, $rest_b),+),
|
|
|
|
ordering => ordering
|
|
|
|
}
|
|
|
|
};
|
2014-12-09 16:44:56 +00:00
|
|
|
($a:expr, $b:expr) => { ($a).partial_cmp(&$b) };
|
2014-06-18 06:25:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-19 08:51:14 +00:00
|
|
|
macro_rules! lexical_cmp {
|
|
|
|
($a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
2014-12-09 16:44:56 +00:00
|
|
|
match ($a).cmp(&$b) {
|
2013-05-19 08:51:14 +00:00
|
|
|
Equal => lexical_cmp!($($rest_a, $rest_b),+),
|
|
|
|
ordering => ordering
|
|
|
|
}
|
|
|
|
};
|
2014-12-09 16:44:56 +00:00
|
|
|
($a:expr, $b:expr) => { ($a).cmp(&$b) };
|
2013-05-19 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
2017-07-01 23:41:39 +00:00
|
|
|
macro_rules! last_type {
|
|
|
|
($a:ident,) => { $a };
|
|
|
|
($a:ident, $($rest_a:ident,)+) => { last_type!($($rest_a,)+) };
|
|
|
|
}
|
|
|
|
|
2013-05-19 08:51:14 +00:00
|
|
|
tuple_impls! {
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple1 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
2013-08-08 20:07:21 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple2 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple3 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple4 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
|
|
|
(3) -> D
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple5 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
|
|
|
(3) -> D
|
|
|
|
(4) -> E
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple6 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
|
|
|
(3) -> D
|
|
|
|
(4) -> E
|
|
|
|
(5) -> F
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple7 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
|
|
|
(3) -> D
|
|
|
|
(4) -> E
|
|
|
|
(5) -> F
|
|
|
|
(6) -> G
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple8 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
|
|
|
(3) -> D
|
|
|
|
(4) -> E
|
|
|
|
(5) -> F
|
|
|
|
(6) -> G
|
|
|
|
(7) -> H
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple9 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
|
|
|
(3) -> D
|
|
|
|
(4) -> E
|
|
|
|
(5) -> F
|
|
|
|
(6) -> G
|
|
|
|
(7) -> H
|
|
|
|
(8) -> I
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple10 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
|
|
|
(3) -> D
|
|
|
|
(4) -> E
|
|
|
|
(5) -> F
|
|
|
|
(6) -> G
|
|
|
|
(7) -> H
|
|
|
|
(8) -> I
|
|
|
|
(9) -> J
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple11 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
|
|
|
(3) -> D
|
|
|
|
(4) -> E
|
|
|
|
(5) -> F
|
|
|
|
(6) -> G
|
|
|
|
(7) -> H
|
|
|
|
(8) -> I
|
|
|
|
(9) -> J
|
|
|
|
(10) -> K
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2014-02-16 09:25:28 +00:00
|
|
|
Tuple12 {
|
2015-03-15 17:15:38 +00:00
|
|
|
(0) -> A
|
|
|
|
(1) -> B
|
|
|
|
(2) -> C
|
|
|
|
(3) -> D
|
|
|
|
(4) -> E
|
|
|
|
(5) -> F
|
|
|
|
(6) -> G
|
|
|
|
(7) -> H
|
|
|
|
(8) -> I
|
|
|
|
(9) -> J
|
|
|
|
(10) -> K
|
|
|
|
(11) -> L
|
2013-05-18 09:43:14 +00:00
|
|
|
}
|
2013-05-19 08:51:14 +00:00
|
|
|
}
|