Why splitter() doesn't work?

Mehrdad wfunction at hotmail.com
Sun Oct 14 16:10:10 PDT 2012


On Sunday, 14 October 2012 at 23:01:02 UTC, Jonathan M Davis 
wrote:
> On Sunday, October 14, 2012 22:09:43 Peter Alexander wrote:
>> I wonder if a better design for splitter would automatically
>> allocate an array when the input range doesn't support slicing?
>
> We generally try and avoid any kind of allocation like that in 
> std.algorithm. We leave it up to the programmer to do that. 
> Otherwise, you'd end up with all kinds of invisible performance 
> hits. And it's doubly bad for anyone trying to avoid using the 
> GC.
>
> - Jonathan M Davis


Well, you don't need to automatically allocate anything.

As long as you require the input to be a forward range, you can 
simply iterate over it over and over again every time you want to 
return front(). AFAICT no need to store anything anywhere.


More information about the Digitalmars-d mailing list