Skip to content

Commit 7a7e163

Browse files
committed
Replace int[n] with auto in staticArray examples.
The examples should encourage the most failsafe and DRY staticArray use.
1 parent 52e9170 commit 7a7e163

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

std/array.d

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,17 @@ if (isIterable!Iterable)
391391
@safe pure nothrow unittest
392392
{
393393
import std.range : only;
394-
int[3] arr = only(1, 2, 3).staticArray!3;
394+
auto arr = only(1, 2, 3).staticArray!3;
395+
static assert(is(typeof(arr) == int[3]));
395396
assert(arr == [ 1, 2, 3 ]);
396397
}
397398

398399
/// If the range has more than `n` elements, `staticArray` takes only `n`
399400
@safe pure nothrow unittest
400401
{
401402
import std.range : take, repeat;
402-
int[4] arr = repeat(5).staticArray!4;
403+
auto arr = repeat(5).staticArray!4;
404+
static assert(is(typeof(arr) == int[4]));
403405
assert(arr == [ 5, 5, 5, 5 ]);
404406
}
405407

@@ -413,7 +415,7 @@ pure unittest
413415
assertThrown!AssertError(only(1,2,3).staticArray!5);
414416

415417
// extend the range to the desired length before handing it to staticArray
416-
int[5] arr = only(1,2,3).chain(0.repeat).staticArray!5;
418+
auto arr = only(1,2,3).chain(0.repeat).staticArray!5;
417419
assert(arr == [ 1, 2, 3, 0, 0 ]);
418420
}
419421

@@ -435,7 +437,8 @@ unittest
435437
}
436438
}
437439

438-
int[5] arr = OpApply().staticArray!5;
440+
auto arr = OpApply().staticArray!5;
441+
static assert(is(typeof(arr) == int[5]));
439442
assert(arr == [ 0, 1, 2, 3, 4 ]);
440443
}
441444

0 commit comments

Comments
 (0)