Add support implicit conversion between types

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Sep 6 10:05:47 PDT 2013


On Fri, Sep 06, 2013 at 05:14:48PM +0200, ilya-stromberg wrote:
> 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.

Hmm, I see. This is an unfortunate limitation. In C++, writing int(123)
actually works. Looks like D is lacking in this area. :-(


T

-- 
Answer: Because it breaks the logical sequence of discussion.
Question: Why is top posting bad?


More information about the Digitalmars-d mailing list