<br><br><div class="gmail_quote">On Sat, May 29, 2010 at 15:54, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:andrei@erdani.com">andrei@erdani.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Typo: "Attenpting" (at least two places)<br>
<br>
I think popBack for bidirectional ranges is broken. Consider I have a range of 1000 elements and I take 5 of them. Then popBack would have to back off 996 elements. That is not what your code is doing, and it would not satisfy the complexity requirements of popBack.<br>
<br>
Please keep the popBack code only for random-access ranges.<br>
<br>
<br>
Thanks,<br><font color="#888888">
<br>
Andrei</font><div><div></div><br></div></blockquote><div><br>Yes, I think that's why in the bug report I posted something that defined back/popBack only for bidir ranges even though it was an 'overspecification'.<br>
AKAIK, there is no clean way to define them otherwise.<br><br> Steve:<br>> Arguably, Take should never support back and popBack. <br>> If you have a
random access range, why wouldn't you just do r[0..3]?<br><br>Because your range may not have opSlice defined. And is such a slice always lazy? The difficulty in std.range/algo is to keep them lazy as much as possible. Eager versions of these functions are easy to do (and could well be part of std.array or std.algo.eager)<br>
<br>I *think* at some time I had a version of take that changed if the range has slicing and returned just r[0..n]. But I dropped it not long afterwards, maybe because it caused too much headache with the changing type (R or Take!R), even hiding it in a template. <br>
<br>Anyway, the idea was just to extend map/filter/take and such as much as cleanly possible (see bugs #3871 and #3872), to have them play nice when composed.<br>map particularly cries out to have opIndex/back/popBack/opSlice defined when possible. It a workhorse, used in many range transformation.<br>
<br>Philippe<br><br><br>
</div></div>