Ranges of char and wchar

Jesse Phillips via Digitalmars-d digitalmars-d at puremagic.com
Tue May 13 11:27:27 PDT 2014


On Thursday, 8 May 2014 at 17:46:06 UTC, Andrei Alexandrescu 
wrote:
> A discussion is building around 
> https://github.com/D-Programming-Language/phobos/pull/2149, 
> which is a nice initiative by Walter to allow Phobos users to 
> avoid or control memory allocation.
>
> First instance of the pull request copied the inputs into an 
> output range.
>
> The second instance (right now) creates an input range that 
> lazily creates the result. The element type of that range is 
> the encoding type of the first argument (i.e. char or wchar 
> most of the time). This is different from string/wstring/etc 
> element-wise iteration because it'll be done code unit-wise, 
> not code point-wise.

I'm with H. S. Teoh that we should prefer the input range 
approach. My limited experience with output ranges suggests to me 
that they really need to be the end point, where the data is 
actually leaving the program (writing to disk, over a network). 
And as Teoh mentions, if you need it in specific memory you can 
copy an input range into it.

D is already fairly lazy, and .array() is great for doing eager 
evaluation into the GC. For strings having something similar 
which allows for the original encoding to remain would be good.


More information about the Digitalmars-d mailing list