void testForwardRange(R, E)(R range, E[] content)
{
// Deliberately not contraints, because this *is* a test,
after all.
// *Or* maybe it just auto-detects range type and leaves it
// up to the user to check for "isForwardRange!R" or
whatever.
static assert(isForwardRange!R);
static assert(is(ElementTypeOf!R == E));
static if(hasLength!R)
assert(range.length == content.length);
foreach(i; 0...content.length)
{
assert(range.front == content[i]);
range.popFront();
}
// More tests
}
Would it make sense to just name the function testRange and have
it test conformance for any range primitives that the type
supports? Your example already uses static "if(hasLenght!R)" for
length, it may be a good idea to expand that.