range chunks

Philippe Sigaud philippe.sigaud at gmail.com
Fri Aug 6 11:59:17 PDT 2010

On Fri, Aug 6, 2010 at 19:48, Steven Schveighoffer <schveiguy at yahoo.com>wrote:

> On Fri, 06 Aug 2010 13:33:09 -0400, Philippe Sigaud <
> philippe.sigaud at gmail.com> wrote:
>  Here is what I cooked, it's still a bit rough around the edges. It has an
>> optional step argument, to see how many elements to jump.
> [snip]
>     ElementType!R[] front() @property { return array(take(range, n));} //
> I'd change this to just return take(range, n).  Rule #1 in writing
> efficient D code, avoid the heap when you can :)

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?

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."

Maybe the type produced could be decided by a policy: lazy, dynamic array...
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...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100806/8900e0d0/attachment.html>

More information about the Digitalmars-d mailing list