Another cool mini-project: advance a range within n steps from its end

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 4 14:33:14 PST 2015


On 12/04/2015 03:01 PM, Jacob Carlborg wrote:
> On 2015-12-04 17:37, Andrei Alexandrescu wrote:
>> Like "tail" in Unix. Given a range R r and a number size_t n, return a
>> TakeExactly!R that's r at no more than n steps from its end:
>>
>> TakeExactly!R advanceWithin(R)(R r, size_t n)
>> if (isForwardRange!R);
>>
>> Invariant:
>>
>> assert(r.advanceWithin(n).length <= n);
>>
>> Implementation would send a scout range ahead, etc.
>>
>> I didn't file an issue for it, but it's a great function to have.
>
> retro + take?

Try it! -- Andrei


More information about the Digitalmars-d mailing list