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.
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.
11 //! Implementations of things like `Eq` for fixed-length arrays
12 //! up to a certain length. Eventually we should able to generalize
15 #![experimental] // not yet reviewed
18 use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
24 // macro for implementing n-ary tuple functions and operations
25 macro_rules! array_impls {
29 impl<T:Copy> Clone for [T; $N] {
30 fn clone(&self) -> [T; $N] {
35 #[unstable = "waiting for Show to stabilize"]
36 impl<T:fmt::Show> fmt::Show for [T; $N] {
37 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38 fmt::Show::fmt(&self[], f)
43 impl<A, B> PartialEq<[B; $N]> for [A; $N] where A: PartialEq<B> {
45 fn eq(&self, other: &[B; $N]) -> bool {
49 fn ne(&self, other: &[B; $N]) -> bool {
55 impl<'a, A, B, Rhs> PartialEq<Rhs> for [A; $N] where
60 fn eq(&self, other: &Rhs) -> bool { PartialEq::eq(self[], &**other) }
62 fn ne(&self, other: &Rhs) -> bool { PartialEq::ne(self[], &**other) }
66 impl<'a, A, B, Lhs> PartialEq<[B; $N]> for Lhs where
71 fn eq(&self, other: &[B; $N]) -> bool { PartialEq::eq(&**self, other[]) }
73 fn ne(&self, other: &[B; $N]) -> bool { PartialEq::ne(&**self, other[]) }
77 impl<T:Eq> Eq for [T; $N] { }
80 impl<T:PartialOrd> PartialOrd for [T; $N] {
82 fn partial_cmp(&self, other: &[T; $N]) -> Option<Ordering> {
83 PartialOrd::partial_cmp(&self[], &other[])
86 fn lt(&self, other: &[T; $N]) -> bool {
87 PartialOrd::lt(&self[], &other[])
90 fn le(&self, other: &[T; $N]) -> bool {
91 PartialOrd::le(&self[], &other[])
94 fn ge(&self, other: &[T; $N]) -> bool {
95 PartialOrd::ge(&self[], &other[])
98 fn gt(&self, other: &[T; $N]) -> bool {
99 PartialOrd::gt(&self[], &other[])
104 impl<T:Ord> Ord for [T; $N] {
106 fn cmp(&self, other: &[T; $N]) -> Ordering {
107 Ord::cmp(&self[], &other[])
116 10 11 12 13 14 15 16 17 18 19
117 20 21 22 23 24 25 26 27 28 29