Add support implicit conversion between types
ilya-stromberg
ilya-stromberg-2009 at yandex.ru
Fri Sep 6 08:14:48 PDT 2013
On Friday, 6 September 2013 at 14:26:17 UTC, H. S. Teoh wrote:
> I thought the usual D idiom was to write factorial(5) and
> factorial(BigInt(5)) and let the compiler figure out which
> template
> instance you wanted?
Yes, but it isn't always possible.
>> It can be critical for more complex cases, when you call one
>> generic
>> function from another one, like this:
>>
>> unittest
>> {
>> alias TypeTuple!(byte, ubyte, short, ushort, int, uint,
>> long,
>> ulong, BigInt) IntegralTypeList;
>>
>> foreach(T; IntegralTypeList)
>> {
>> assert(factorial!T(3) == 6);//Error: factorial (BigInt
>> number)
>> is not callable using argument types (int)
>
> You could just write factorial(T(3)) ?
No, I have the error:
Error: function expected before (), not byte of type byte
Error: function expected before (), not ubyte of type ubyte
Error: function expected before (), not short of type short
Error: function expected before (), not ushort of type ushort
Error: function expected before (), not int of type int
Error: function expected before (), not uint of type uint
Error: function expected before (), not long of type long
Error: function expected before (), not ulong of type ulong
As monarch_dodra pointed above, we haven't got "uniform
construction" support.
More information about the Digitalmars-d
mailing list