Adding a read primitive to ranges

Freddy via Digitalmars-d digitalmars-d at puremagic.com
Mon May 4 18:28:02 PDT 2015


On Tuesday, 5 May 2015 at 00:50:44 UTC, Freddy wrote:
> ----
> void func(R)(R range){//expects range of strings
>     string[] elms=range.read(5);
>     string[] elms2=range.read(9);
>     /++..++/
> }
>
>
> void caller(){
>     auto file=...;//unbuffered file
>     file.map!(a=>a.to!string).func();
> }
> ----
Wait, Bad example,
----
void func(R)(R range){//expects range of ubyte
     ubyte[] data=range.read(VERY_BIG_NUMBER);
     ubyte[] other_data=range.read(OTHER_VERY_BIG_NUMBER);
}
----
which would be more optimal for a file but still works for other 
ranges, compared to looping though the ranges read appending to 
data.


More information about the Digitalmars-d mailing list