template specialization

Ellery Newcomer ellery-newcomer at utulsa.edu
Tue Jun 8 15:15:22 PDT 2010


On 06/08/2010 05:01 PM, Robert Clipsham wrote:
> On 08/06/10 22:25, Larry Luther wrote:
>> Q: Is this the way it's supposed to be?
>
> Yes, byte implicitly casts to ubyte so it's accepted. Try switching the
> templates round, they will both be byte. The way around this is to add
> template constraints to the templates:
>
> void get(T:ubyte)(T[] buffer) if( is( T == ubyte ) ) { }
> void get(T:byte)(T[] buffer) if( is( T == byte ) ) { }
>
> etc.
>
> Hope this helps,
>
> Robert

bit odd though, since byte[] isn't implicitly convertible to ubyte[].

no wait! yes it is!

void get(T:ubyte[])(T t){}
..
get(new byte[](1));

no wait! no it isn't!

ubyte[] u = new byte[](1);


and is it just me, or does the following silently cast away immutability?

get("hi mom!");


More information about the Digitalmars-d-learn mailing list