Just had this error crop up. I just wanted to check whether this is correct behavior as I don't know the details of D's templates. I'm using DMD 2.047 to compile with no flags.

struct A(uint N) { }
void   b(uint N)() { }
void   c(uint N)(A!(N) a) { }

void main()
{
  A!(1) a;  // OK
  b!(1)();  // OK
  c!(1)(f); // Error - cannot implicitly convert A!(1) to A!(N)
  c(a);     // Error - cannot implicitly convert A!(1) to A!(N)
}


Are those errors correct?

If so, why can I instantiate 'A' and 'b' with a signed int parameter, but can't instantiate 'c'?

It seems that the uint-ness of the template parameter is only enforced when there is an argument involved, but I don't understand the reasoning behind this (if any). I would expect either all of these to compile, or none to compile.

Thanks in advance.

Reply via email to