range chunks
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Aug 6 13:11:05 PDT 2010
Steven Schveighoffer wrote:
> On Fri, 06 Aug 2010 14:59:17 -0400, Philippe Sigaud
> <philippe.sigaud at gmail.com> wrote:
>
>> 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?
>
> Doesn't take return a random-access range if the original is a random
> access range?
>
> I would actually expect take(range, n) to return range[0..n] if range
> supports that.
It does since recently.
Andrei
More information about the Digitalmars-d
mailing list