www.digitalmars.com Sargon Component Library for D




sargon.array.asinputrange

This module contains asInputRange().

Authors:
Walter Bright

License:
Boost License 1.0

Source:
src/sargon/array/asinputrange.d

ref auto asInputRange(E)(E[] a);
Turn an array into an InputRange, useful for unittesting.

Parameters:
E[] a is an array of elements of type E

Returns:
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);
}

void testInputRange(R)(R r) if (isInputRange!R);
Takes an InputRange as input and verifies that it can be iterated following protocol.

Parameters:
R r is an InputRange

Examples:
testInputRange(asInputRange("betty"));