|
| 1 | +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +/*! |
| 12 | + * Implementations of things like `Eq` for fixed-length arrays |
| 13 | + * up to a certain length. Eventually we should able to generalize |
| 14 | + * to all lengths. |
| 15 | + */ |
| 16 | + |
| 17 | +#![doc(primitive = "tuple")] |
| 18 | +#![stable] |
| 19 | + |
| 20 | +#[unstable = "this is just a documentation module and should not be part \ |
| 21 | + of the public api"] |
| 22 | +pub use unit; |
| 23 | + |
| 24 | +use cmp::*; |
| 25 | +use option::{Option}; |
| 26 | + |
| 27 | +// macro for implementing n-ary tuple functions and operations |
| 28 | +macro_rules! array_impls { |
| 29 | + ($($N:expr)+) => { |
| 30 | + $( |
| 31 | + #[unstable = "waiting for PartialEq to stabilize"] |
| 32 | + impl<T:PartialEq> PartialEq for [T, ..$N] { |
| 33 | + #[inline] |
| 34 | + fn eq(&self, other: &[T, ..$N]) -> bool { |
| 35 | + self[] == other[] |
| 36 | + } |
| 37 | + #[inline] |
| 38 | + fn ne(&self, other: &[T, ..$N]) -> bool { |
| 39 | + self[] != other[] |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + #[unstable = "waiting for Eq to stabilize"] |
| 44 | + impl<T:Eq> Eq for [T, ..$N] { } |
| 45 | + |
| 46 | + #[unstable = "waiting for PartialOrd to stabilize"] |
| 47 | + impl<T:PartialOrd> PartialOrd for [T, ..$N] { |
| 48 | + #[inline] |
| 49 | + fn partial_cmp(&self, other: &[T, ..$N]) -> Option<Ordering> { |
| 50 | + PartialOrd::partial_cmp(&self[], &other[]) |
| 51 | + } |
| 52 | + #[inline] |
| 53 | + fn lt(&self, other: &[T, ..$N]) -> bool { |
| 54 | + PartialOrd::lt(&self[], &other[]) |
| 55 | + } |
| 56 | + #[inline] |
| 57 | + fn le(&self, other: &[T, ..$N]) -> bool { |
| 58 | + PartialOrd::le(&self[], &other[]) |
| 59 | + } |
| 60 | + #[inline] |
| 61 | + fn ge(&self, other: &[T, ..$N]) -> bool { |
| 62 | + PartialOrd::ge(&self[], &other[]) |
| 63 | + } |
| 64 | + #[inline] |
| 65 | + fn gt(&self, other: &[T, ..$N]) -> bool { |
| 66 | + PartialOrd::gt(&self[], &other[]) |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + #[unstable = "waiting for Ord to stabilize"] |
| 71 | + impl<T:Ord> Ord for [T, ..$N] { |
| 72 | + #[inline] |
| 73 | + fn cmp(&self, other: &[T, ..$N]) -> Ordering { |
| 74 | + Ord::cmp(&self[], &other[]) |
| 75 | + } |
| 76 | + } |
| 77 | + )+ |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +array_impls! { |
| 82 | + 0 1 2 3 4 5 6 7 8 9 |
| 83 | + 10 11 12 13 14 15 16 17 18 19 |
| 84 | + 20 21 22 23 24 25 26 27 28 29 |
| 85 | + 30 31 32 |
| 86 | +} |
| 87 | + |
0 commit comments