<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


In general, if you want to do something once per element which involves side<br>
effects, I would advise using foreach rather than trying to put it into a<br>
range. </blockquote><div><br></div><div>using foreach breaks UFCS chains, and also ElementType != ForeachType</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

But if you insist on doing so, the side effect should go in popFront,<br>
not front, or the side effects will often be happening more than once per<br>
element.<br></blockquote><div><br></div><div>This won't work if side effect should occur _before_ element is popped. And this is very awkward to use with map/reduce/filter, as it forces one to write explicitly a range wrapper, defeating purpose of reusing phobos components. Having to write a custom range (with pop/front/popBack etc) just to support lambdas with side effects is a pain. </div>

<div><br></div><div>I'd like to propose a generic solution for that, see the email I just sent:</div><div><br></div><div>"std.range.cacheFront proposal&working code: wraps a range to enforce front is called only once"<br>
</div></div></div></div>