std.range.cacheFront proposal&working code: wraps a range to	enforce front is called only once
    Chris 
    wendlec at tcd.ie
       
    Thu Oct 24 08:55:22 PDT 2013
    
    
  
On Thursday, 24 October 2013 at 15:40:22 UTC, Dicebot wrote:
> On Thursday, 24 October 2013 at 15:36:59 UTC, Chris wrote:
>> How do you define side effects? After all ranges manipulate, 
>> reformat or restructure data.
>
> They should do it in popFront. I'd consider any `front` that 
> does anything but accessing cached value suspicious.
So code like
auto front() {
   doSomething();
   return range[0];
}
should go into
void popFront() {
   doSomething();
   range = range[1..$];
}
    
    
More information about the Digitalmars-d
mailing list