how to instantiate explicitly template parameters in struct A(T1){this(T2)(){...}}

Steven Schveighoffer schveiguy at yahoo.com
Mon May 13 21:08:26 PDT 2013


On Mon, 13 May 2013 23:34:39 -0400, Timothee Cour  
<thelastmammoth at gmail.com> wrote:

> A)
> The behavior of __ctor (whether or not documented) seems broken /  
> unreliable:
>
> struct A{this(T)(T x){}}
>
> void fun(T){
>   auto a=A.__ctor!(int)(1);
> }
> void main(){
>   auto a=A.__ctor!(int)(1); //ok
>   fun!int(); //Error: type A is not an expression
> }

__ctor is a 'this' call, it needs a this (BTW, I get different errors than  
you):

struct A{this(T)(T x){}}

void fun(T)(){
       A a;
       a.__ctor!(int)(1);
}
void main(){
     A a;
     a.__ctor!(int)(1);
       fun!int();
}

Not sure how you would do that in one line (and I assume you had a typo in  
fun(T) since it wasn't valid syntax).

> B)
> Why not use 'this' instead of '__ctor', and make it documented (and
> reliable, ie work in the above case) ?
> I don't see how that could create ambiguity, and that would solve the
> problem raised in this thread.

You could do that.  It may have some ambiguous syntax implications.

-Steve


More information about the Digitalmars-d-learn mailing list