https://issues.dlang.org/show_bug.cgi?id=4660

--- Comment #8 from [email protected] ---
The point is that writeln treats both lazy and non-lazy ranges generically,
that's why it does not distinguish between them. If you really wanted to
distinguish between them, you could do this:

-----
string getFmtString(R)(R range)
    if (isInputRange!R)
{
    // Here we assume eager == array
    static if (is(R : A[], A))
        return "[%(%s, %)]";
    else
        return "[%(%s; %)]";
}

auto myRange = ...;
writefln(myRange.getFmtString, myRange); // this will do what you want,
generically
-----

Note that the above code is not 100% fool-proof; for example, R could be a
wrapper struct around an array, so the static if wouldn't identify it as an
eager range, but in fact it's actually eager. Or it could be a struct that
generates data in blocks of 500 elements each time -- would that qualify as
lazy or eager? Basically, there really isn't a 100% foolproof, generic way to
determine if something is eager or not. In fact, I don't know of a definition
of lazy vs. eager that covers 100% of the cases.

--

Reply via email to