asInputRange

Turn an array into an InputRange, useful for unittesting.

ref
asInputRange
(
E
)
(
E[] a
)

Parameters

a E[]

is an array of elements of type E

Return Value

Type: auto ref

an InputRange

Examples

import std.range;

static assert(isInputRange!(typeof(asInputRange("hello"))));

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

{   // various boundary conditions
    auto r = "foo".asInputRange;
    assert(!r.empty);
    assert(!r.empty);
    r.popFront();
    r.popFront();
    r.popFront();
    assert(r.empty);
}

Meta