File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -313,9 +313,42 @@ impl<T:Ord, const N: usize> Ord for [T; N] {
313313 }
314314}
315315
316+ /*
317+
316318#[stable(since = "1.4.0", feature = "array_default")]
317319impl<T, const N: usize> Default for [T; N] where T: Default {
318320 fn default() -> [T; N] {
319321 [T::default(); N]
320322 }
321323}
324+
325+ // FIXME: This doesn't work now because it's using negative bound.
326+
327+ #[stable(since = "1.4.0", feature = "array_default")]
328+ impl<T> Default for [T; 0] where T: !Default {
329+ fn default() -> [T; 0] {
330+ []
331+ }
332+ }
333+
334+ */
335+
336+ macro_rules! array_impl_default {
337+ { $n: expr, $t: ident $( $ts: ident) * } => {
338+ #[ stable( since = "1.4.0" , feature = "array_default" ) ]
339+ impl <T > Default for [ T ; $n] where T : Default {
340+ fn default ( ) -> [ T ; $n] {
341+ [ $t:: default ( ) , $( $ts:: default ( ) ) ,* ]
342+ }
343+ }
344+ array_impl_default!{ ( $n - 1 ) , $( $ts) * }
345+ } ;
346+ { $n: expr, } => {
347+ #[ stable( since = "1.4.0" , feature = "array_default" ) ]
348+ impl <T > Default for [ T ; $n] {
349+ fn default ( ) -> [ T ; $n] { [ ] }
350+ }
351+ } ;
352+ }
353+
354+ 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 }
You can’t perform that action at this time.
0 commit comments