how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();

mw mingwu at gmail.com
Mon Jun 22 21:45:11 UTC 2020


On Monday, 22 June 2020 at 21:22:10 UTC, H. S. Teoh wrote:
> On Mon, Jun 22, 2020 at 08:51:49PM +0000, mw via 
> Digitalmars-d-learn wrote: [...]
>> >    auto line = range.front;
>> >    range.popFront;  // pop immediately
> [...]
>
> This is dangerous, because it assumes .front is not invalidated 
> by .popFront.  It will not work, for example, with byLine 
> because .front returns a buffer which is reused by .popFront (a 
> so-called "transient range").

This is valid reason, but as I replied in the other post: it 
depends on the actual underlying data structure and usage 
scenario, so:

"why not provide a popAndReturnFront(), and let the user decide 
based on his/her own actual usage?"






More information about the Digitalmars-d-learn mailing list