[phobos] UnbufferedFile, or, abstracting the File ranges

Andrei Alexandrescu andrei at erdani.com
Tue May 11 11:18:59 PDT 2010


Lars Tandle Kyllingstad wrote:
> Yeah, the ubyte functions were just examples.  My intention was to use
> templates:
> 
>   size_t read(T)(ref T[] b);
>   size_t write(T)(T[] b);
> 
> Then you get a sensible error message if the number of raw bytes read
> isn't a multiple of the size of your target type.  Also, the returned
> number is the length of the resulting array, and not the number of raw
> bytes read.
> 
> Thanks for the tips! :)

That would make the functions type-unsafe. You'd need to limit T to 
types that have no pointers (at least). Whoa, serialization rears its 
ugly head.

Andrei


More information about the phobos mailing list