Thread overview
[Issue 13409] std.range.padLeft/Right
Aug 31, 2014
Peter Alexander
Oct 22, 2015
Jack Stouffer
Oct 23, 2015
Jack Stouffer
Mar 09, 2016
Jack Stouffer
August 31, 2014
https://issues.dlang.org/show_bug.cgi?id=13409

monarchdodra@gmail.com changed:

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

--- Comment #1 from monarchdodra@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...

--
August 31, 2014
https://issues.dlang.org/show_bug.cgi?id=13409

--- Comment #2 from Peter Alexander <peter.alexander.au@gmail.com> ---
(In reply to monarchdodra from comment #1)
> Is there a use case for this outside of string formatting?

I need it for padding data buffers out.


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

I think it is justified. When using chain/repeat, it isn't immediately clear what you are doing, whereas padLeft/Right are self documenting. If I needed to do this, I would create padLeft/Right myself as separate functions to make it clear. If people are going to do this then it might as well be in Phobos, in my opinion.

Also, padRight with an input range without length cannot be implemented in terms of other ranges, I think (not easily anyway).

I actually only need padRight, but I feel padLeft should exist for symmetry.


> 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...

Random access is unnecessary. You only need hasLength + input range (see proposal). Incidentally, these kind of subtleties are a good reason why Phobos should provide them instead of relying on users to do so.

The case for input range with no length for padRight is actually exactly what prompted me to create this. I'm generating some data of unknown length (it is lazily generated) that I want to copy into a pre-sized buffer, and then fill the rest of the buffer with 0's.

--
October 22, 2015
https://issues.dlang.org/show_bug.cgi?id=13409

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |15236

--
October 22, 2015
https://issues.dlang.org/show_bug.cgi?id=13409
Issue 13409 depends on issue 15236, which changed state.

Issue 15236 Summary: std.range.chain cannot chain a std.range.repeat string https://issues.dlang.org/show_bug.cgi?id=15236

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--
October 23, 2015
https://issues.dlang.org/show_bug.cgi?id=13409

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jack@jackstouffer.com

--- Comment #3 from Jack Stouffer <jack@jackstouffer.com> ---
Part one: https://github.com/D-Programming-Language/phobos/pull/3765

--
March 09, 2016
https://issues.dlang.org/show_bug.cgi?id=13409

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--
March 24, 2016
https://issues.dlang.org/show_bug.cgi?id=13409

--- Comment #4 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/38c243cf91357c4986f01c472128e527dcb7422a Fix Issue 13409: add padLeft and padRight

https://github.com/D-Programming-Language/phobos/commit/1651c7864f97ac582a0480850904ec3ebcd0194c Merge pull request #3765 from JackStouffer/pad

[Issue 13409] std.range.padLeft/Right

--
March 24, 2016
https://issues.dlang.org/show_bug.cgi?id=13409

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--