[Issue 13409] std.range.padLeft/Right

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Aug 31 14:01:19 PDT 2014


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

monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com

--- Comment #1 from monarchdodra at gmail.com ---
Is there a use case for this outside of string formatting?

Also, does it justify having a new range, when the same end result could be had
with chain and repeat?

auto padLeft(R, E)(R r, E e, size_t n)
{
    return chain(repeat(e, n > r.length ? n - r : 0), r)
}

For padLeft, I'm making the assumption that r is random access. If we want to
accept forward range (input is not possible), then we have to use
r.save.walkLength(), presuming the extra complexity is acceptable.

The only case where your proposal could make sense, is for padRight on a pure
input range (no length, no save). But that's one hell of a particular case...

--


More information about the Digitalmars-d-bugs mailing list