asForwardRange

Turn an array into a ForwardRange, useful for unittesting.

ref
asForwardRange
(
E
)
(
E[] a
)

Parameters

a E[]

is an array of elements of type E

Return Value

Type: auto ref

a ForwardRange

Examples

import std.range;

static assert(isForwardRange!(typeof(asForwardRange("hello"))));

void testrange(string f, string result)
{
    char[50] s;
    int i;
    foreach (c; f.asForwardRange())
    {
        s[i++] = c;
    }
    assert(s[0 .. i] == result);
}
testrange("file", "file");

{   // various boundary conditions
    auto r = "foo".asForwardRange;
    auto s = r.save;
    assert(!r.empty);
    assert(!r.empty);
    r.popFront();
    r.popFront();
    r.popFront();
    assert(r.empty);

    assert(!s.empty);
    assert(!s.empty);
    s.popFront();
    s.popFront();
    s.popFront();
    assert(s.empty);
}

Meta