Possible bug

Ali Çehreli acehreli at yahoo.com
Mon Mar 25 14:13:58 PDT 2013


On 03/25/2013 12:40 PM, Steven Schveighoffer wrote:
 > On Mon, 25 Mar 2013 11:31:17 -0400, Ali Çehreli <acehreli at yahoo.com> 
wrote:
 >
 >> This design allows templated constructors:
 >>
 >> struct S // <-- not a template
 >> {
 >> this(T)(T t) // <-- template
 >> {
 >> // ...
 >> }
 >>
 >> // ...
 >> }
 >>
 >> The same in C++...
 >
 > Templated constructors would not be disallowed if you allowed IFTI on
 > templated structs/classes without templated constructors.

It would complicate matters: The parameter would be for the constructor 
if the constructor were a template, for the struct otherwise.

 > When you decompose constructors, they are simply fucntions, and IFTI
 > exists on functions. The same should be allowed for constructors.

I completely agree and that's my point. :) The template parameter list 
of the constructor should stay with the constructor.

 > There is almost no difference between this:
 >
 > template foo(T){
 > void foo(T t) {}
 > }
 >
 > and this:
 >
 > struct foo(T){
 > this(T t) {}
 > }

Actually, the latter is a shorthand for this:

template S(T)
{
     struct S
     {
         T t;

         this(U)(U)
         {}
     }
}

As you see, T comes from the outer template and U stays with the 
constructor. It allows the following use:

void main()
{
     auto s = S!int(byte.init);
}

 >
 > -Steve

Ali



More information about the Digitalmars-d-learn mailing list