On Thursday, 24 July 2014 at 09:38:14 UTC, bearophile wrote:
francesco cattoglio:
should this code compile? I understand that the literal "1" is
"int" therefore it can screw type deduction, but I wonder if
the compiler should be smart enough to deduce it correctly.
To keep both the compiler and programmers sane, D templates
don't perform implicit type conversions. This sometimes is not
handy, but on the whole saves from a large number of troubles.
So you can write (D V.2.066):
Vector!ubyte(ubyte(1), ubyte(1), ubyte(1));
Or you can create a little helper function that makes that code
more DRY.
Bye,
bearophile
I expected such an answer and I do understand the decisions
behind it. Yet, you gave me a really GOOD news! Having to write
cast(ubyte) 1 was way too much verbose for my liking, while the
new ubyte(1) is reasonable enough.