bearophile can say "i told you so" (re uint->int implicit conv)

Benjamin Thaut code at benjamin-thaut.de
Fri Mar 29 11:26:41 PDT 2013


Am 29.03.2013 13:10, schrieb Adam D. Ruppe:
>
> Is that fairly new in D? I'm almost certain I tried it and it didn't
> work when I originally wrote this code (which was a couple years ago).
>

Yes it's fairly new. I think dmd 2.060 or something along that line. I 
tend to use it a lot because its so awesome ^^

For example my streaming interface for binary streams:


interface IInputStream
{
   public:
     final size_t read(T)(ref T data) if(!thBase.traits.isArray!T)
     {
       static assert(!is(T == const) && !is(T == immutable), "can not 
read into const / immutable value");
       return readImpl((cast(void*)&data)[0..T.sizeof]);
     }

     final size_t read(T)(T data) if(thBase.traits.isArray!T)
     {
       static assert(!is(typeof(data[0]) == const) && 
!is(typeof(data[0]) == immutable), "can not read into const / immutable 
array");
       return readImpl((cast(void*)data.ptr)[0..(arrayType!T.sizeof * 
data.length)]);
     }

     size_t skip(size_t bytes);

   protected:
     size_t readImpl(void[] buffer);
}


Kind Regards
Benjamin Thaut


More information about the Digitalmars-d mailing list