Skip to content

Commit

Permalink
Change pack example to something simpler
Browse files Browse the repository at this point in the history
The original example for pack has too much stuff going on. Replacing it with a slimmer version that makes it a bit more clear what the impact of pack is. In particular, I feel like the asserts for shapes are necessary to make it obvious.
  • Loading branch information
jmh530 committed Jul 21, 2016
1 parent 8dbad58 commit 1ab23fa
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions std/experimental/ndslice/selection.d
Expand Up @@ -96,6 +96,26 @@ template pack(K...)
}

///
@safe @nogc pure nothrow unittest
{
import std.experimental.ndslice : sliced, Slice, pack;
import std.range: iota;

auto r = (3 * 4 * 5 * 6).iota;
auto a = r.sliced(3, 4, 5, 6);
auto b = a.pack!(2);

assert(b.shape == [3, 4]);
assert(b[0][0].shape == [5, 6]);

assert(a == b);

alias R = typeof(r);
static assert(is(typeof(b) == typeof(a.pack!2)));
static assert(is(typeof(b) == Slice!(2, Slice!(3, R))));
}


@safe @nogc pure nothrow unittest
{
import std.experimental.ndslice.slice;
Expand Down

0 comments on commit 1ab23fa

Please sign in to comment.