<div class="gmail_quote">On Fri, Aug 6, 2010 at 19:48, Steven Schveighoffer <span dir="ltr"><<a href="mailto:schveiguy@yahoo.com">schveiguy@yahoo.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;">
<div class="im">On Fri, 06 Aug 2010 13:33:09 -0400, Philippe Sigaud <<a href="mailto:philippe.sigaud@gmail.com" target="_blank">philippe.sigaud@gmail.com</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Here is what I cooked, it's still a bit rough around the edges. It has an<br>
optional step argument, to see how many elements to jump.<br>
</blockquote>
<br></div>
[snip]<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
ElementType!R[] front() @property { return array(take(range, n));} //<br>
</blockquote>
<br></div>
I'd change this to just return take(range, n). Rule #1 in writing efficient D code, avoid the heap when you can :)<br></blockquote><div><br>Hmm, good idea. And that way, if n is big, you get a lazy range. But you lose the random access and such. I guess the user will call map!array() if she wants to get arrays?<br>
<br>Intially, I had a cache, but I ran into problems to initiate it correctly and told myself "Hey, it's a 10' function, don't sweat it, post it already, if that may help."<br><br>Maybe the type produced could be decided by a policy: lazy, dynamic array...<br>
In a version I use, the n arg is a template arg and the range returns tuples. If found that easier to deal with: from a tuple, you can easily create and array (static, or dynamic), if you want to. And I can easily use it as a function argument list...<br>
<br>Philippe<br><br></div></div>