Skip to content

Commit

Permalink
Replace int[n] with auto in staticArray examples.
Browse files Browse the repository at this point in the history
The examples should encourage the most failsafe and DRY staticArray use.
  • Loading branch information
rcorre committed Apr 6, 2016
1 parent 52e9170 commit 7a7e163
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,17 @@ if (isIterable!Iterable)
@safe pure nothrow unittest
{
import std.range : only;
int[3] arr = only(1, 2, 3).staticArray!3;
auto arr = only(1, 2, 3).staticArray!3;
static assert(is(typeof(arr) == int[3]));
assert(arr == [ 1, 2, 3 ]);
}

/// If the range has more than `n` elements, `staticArray` takes only `n`
@safe pure nothrow unittest
{
import std.range : take, repeat;
int[4] arr = repeat(5).staticArray!4;
auto arr = repeat(5).staticArray!4;
static assert(is(typeof(arr) == int[4]));
assert(arr == [ 5, 5, 5, 5 ]);
}

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

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

Expand All @@ -435,7 +437,8 @@ unittest
}
}

int[5] arr = OpApply().staticArray!5;
auto arr = OpApply().staticArray!5;
static assert(is(typeof(arr) == int[5]));
assert(arr == [ 0, 1, 2, 3, 4 ]);
}

Expand Down

0 comments on commit 7a7e163

Please sign in to comment.