How to best translate this C++ algorithm into D? - refill with range

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 11 09:53:52 PDT 2014


On 11/06/2014 14:45, Nick Treleaven wrote:
> /** Copy up to r.length elements of src to r. */
> auto refill(R, Input)(ref R r, Input src)
> if (isRandomAccessRange!R && isInputRange!Input)

Note this is related to:
std.algorithm.fill(Range1 range, Range2 filler)

Except that fill always fills all of range cyclically:
http://dlang.org/phobos-prerelease/std_algorithm.html#.fill

I've removed 'ref' for r's parameter for consistency with 
std.algorithm's policy to only change content, not topology. Also some 
minor edits:
https://github.com/ntrel/stuff/blob/master/refill.d

I think refill doesn't need to require a random access range now though, 
maybe just a forward range with slicing, like std.range.take.


More information about the Digitalmars-d mailing list