Skip to content

Commit

Permalink
Implement Clone for [T; 0] to [T; 32] if T: Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Dec 4, 2015
1 parent 4f6fe3e commit 19b9ad7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/libcore/array.rs
Expand Up @@ -27,7 +27,7 @@ use default::Default;
use fmt;
use hash::{Hash, self};
use iter::IntoIterator;
use marker::{Copy, Sized, Unsize};
use marker::{Sized, Unsize};
use option::Option;
use slice::{Iter, IterMut, SliceExt};

Expand Down Expand Up @@ -94,13 +94,6 @@ macro_rules! array_impls {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Copy> Clone for [T; $N] {
fn clone(&self) -> [T; $N] {
*self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Hash> Hash for [T; $N] {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
Expand Down Expand Up @@ -210,3 +203,31 @@ macro_rules! array_impl_default {
}

array_impl_default!{32, T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T}

macro_rules! array_impl_clone {
{$n:expr, $t:ident $($ts:ident)*} => {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> Clone for [T; $n] {
fn clone(&self) -> [T; $n] {
let &[ref $t, $(ref $ts),*] = self;
[$t.clone(), $($ts.clone()),*]
}
}
array_impl_clone!{($n - 1), $($ts)*}
};
{$n:expr,} => {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> Clone for [T; 0] {
fn clone(&self) -> [T; 0] {
[]
}
}
};
}

array_impl_clone! { 32,
t00 t01 t02 t03 t04 t05 t06 t07 t08 t09
t10 t11 t12 t13 t14 t15 t16 t17 t18 t19
t20 t21 t22 t23 t24 t25 t26 t27 t28 t29
t30 t31
}
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Expand Up @@ -85,6 +85,7 @@
#![feature(unwind_attributes)]
#![cfg_attr(stage0, feature(simd))]
#![cfg_attr(not(stage0), feature(repr_simd, platform_intrinsics))]
#![feature(slice_patterns)]
#![feature(staged_api)]
#![feature(unboxed_closures)]

Expand Down

0 comments on commit 19b9ad7

Please sign in to comment.