File tree 1 file changed +33
-0
lines changed
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] {
313
313
}
314
314
}
315
315
316
+ /*
317
+
316
318
#[stable(since = "1.4.0", feature = "array_default")]
317
319
impl<T, const N: usize> Default for [T; N] where T: Default {
318
320
fn default() -> [T; N] {
319
321
[T::default(); N]
320
322
}
321
323
}
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