On Saturday, December 10, 2011 13:12:06 Andrei Alexandrescu wrote:
> On 12/10/11 5:27 AM, Walter Bright wrote:
> > On 12/10/2011 3:17 AM, Mehrdad wrote:
> >> Yup, I started using it as soon as Timon mentioned it (thanks for the
> >> suggestion!).
> >> But I was referring to the bug, not to the workaround. :)
> > 
> > It isn't a bug, it is designed to work that way.
> 
> The design is wrong.
> 
> > The type of the
> > instantiation is based on the argument types, not the parameter types.
> 
> This is wrong. The type of parameter is size_t, no two ways about it. It
> is NOT alias.
> 
> > (Note that "2" is the argument and "N" is the parameter.)
> 
> Not that N has type size_t.
> 
> > Hence the message:
> > 
> > Error: cannot implicitly convert expression (m) of type Matrix!(int,2)
> > to Matrix!(int,N)
> 
> The message reflects a mistake.
> 
> >> (I don't understand
> >> why Matrix!(int, cast(int)1) is considered a different instantiation,
> >> when it
> >> can't even be instantiated...)
> > 
> > Yes, it can be instantiated. But it cannot be implicitly converted to
> > type Matrix!(int, cast(uint)1) because they are different types.
> 
> They shouldn't.

Templates should _always_ be instantiated on the _value_ of their arguments. 
In the case such as

template t(T) {}
t!int

the template argument is a type, so the template is instantiated on that type. 
In the case of

template t(int i) {}
t!5

the argument is the value 5, so the template should be instatiated on the 
value 5, regardless of whether the argument is an int or uint or any other 
type implicitly convertible to the template's parameter's type.

I do not understand how Walter could think otherwise. Having

template t(int i) {}
t!5
t!5u

create two separate templates makes no sense. I don't see what value it could 
possible have. And with the addition of CTFE functions or other templates 
whose result is auto, it could cause real problems.

Bug for this: http://d.puremagic.com/issues/show_bug.cgi?id=3467

- Jonathan M Davis

Reply via email to