d - is expression ignores immutable/const? -


i'm using function template void _createattr(t)(args..., in t[]) , testing type of t static if(is(t == char)) in function. when call,

_createattr!char(args...,"somestring") _createattr(args...,"somestring") 

the compiler never complains.

of course know alias string = immutable(char)[]. in first call type of t , supplied argument don't match, in modifier should take care of that. , in second case should infer t = immutable(char). understand it, immutable(char) , char distinct types, compiler passes test in second case.

the compiler (dmd) seems ignore immutableness of chars in string when doing test.

i couldn't find explanation behavior on dlang.org or in d programming language book.

is compiler bug?

no bug, in qualifier expanding const, equally valid both immutable(char) , char, compiler instantiates once.

if t == char, in t[] means const char[] covers both cases template never needs think immutability. pass mutable string function without problems.

if explicitly did !(immutable(char)) use that, , no longer accept mutable one.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -