Stride

Evaluates to an AliasSeq which only contains every nth element from the AliasSeq that was passed in, where n is stepSize.

So, if stepSize is 2, then the result contains every other element from the original. If stepSize is 3, then the result contains every third element from the original. Etc.

If stepSize is negative, then the result is equivalent to using Reverse on the given AliasSeq and then using Stride on it with the absolute value of that stepSize.

If stepSize is positive, then the first element in the original AliasSeq is the first element in the result, whereas if stepSize is negative, then the last element in the original is the first element in the result. Each subsequent element is then the element at the index of the previous element plus stepSize.

template Stride (
int stepSize
Args...
) if (
stepSize != 0
) {}

Examples

static assert(is(Stride!(1, short, int, long) == AliasSeq!(short, int, long)));
static assert(is(Stride!(2, short, int, long) == AliasSeq!(short, long)));
static assert(is(Stride!(3, short, int, long) == AliasSeq!short));
static assert(is(Stride!(100, short, int, long) == AliasSeq!short));

static assert(is(Stride!(-1, short, int, long) == AliasSeq!(long, int, short)));
static assert(is(Stride!(-2, short, int, long) == AliasSeq!(long, short)));
static assert(is(Stride!(-3, short, int, long) == AliasSeq!long));
static assert(is(Stride!(-100, short, int, long) == AliasSeq!long));

alias Types = AliasSeq!(short, int, long, ushort, uint, ulong);
static assert(is(Stride!(3, Types) == AliasSeq!(short, ushort)));
static assert(is(Stride!(3, Types[1 .. $]) == AliasSeq!(int, uint)));
static assert(is(Stride!(-3, Types) == AliasSeq!(ulong, long)));

static assert(is(Stride!(-2, Types) == Stride!(2, Reverse!Types)));

static assert(is(Stride!1 == AliasSeq!()));
static assert(is(Stride!100 == AliasSeq!()));

Meta