Let this() figure out T implicitly?

2012-02-17 Thread kraybourne
Hi! This doesn't work: import std.stdio; class Foo(T) { T t; this(T val) { t = val; } } void main() { auto o = new Foo(5); }

Re: Let this() figure out T implicitly?

2012-02-17 Thread bearophile
kraybourne: Then it compiles. Is it possible to have this() figure out the type some way? Usually people write a small global function helper. (Side note: What _does_ that error message mean? I don't get it.) I think the meaning is: when a class template is not yet instantiated, it's not

Re: Let this() figure out T implicitly?

2012-02-17 Thread Kevin Cox
The error message is saying that you are trying to use Foo as a type but Foo is not a type, it is a template for a type. On Feb 17, 2012 7:20 AM, kraybourne st...@kraybourne.com wrote: Hi! This doesn't work: import std.stdio; class Foo(T) { T t;

Re: Let this() figure out T implicitly?

2012-02-17 Thread kraybourne
On 2/17/12 1:32 PM, bearophile wrote: kraybourne: Then it compiles. Is it possible to have this() figure out the type some way? Usually people write a small global function helper. Hm, so, something like this: Foo!(T) newFoo(T)(T val) { return new

Re: Let this() figure out T implicitly?

2012-02-17 Thread kraybourne
On 2/17/12 1:51 PM, Kevin Cox wrote: The error message is saying that you are trying to use Foo as a type but Foo is not a type, it is a template for a type. Ah, so module.Foo is really not a class, but a template? I think I get it! Thanks! (Is then module.Foo(int).Foo the actual class

Re: Let this() figure out T implicitly?

2012-02-17 Thread Kevin Cox
Yes. At least as the compiler would say. It's a little odd but I believe that is how the D Nam mangling works. I personally just think of Foo!(Class) as the type. On Feb 17, 2012 8:05 AM, kraybourne st...@kraybourne.com wrote: On 2/17/12 1:51 PM, Kevin Cox wrote: The error message is saying

Re: Let this() figure out T implicitly?

2012-02-17 Thread Timon Gehr
On 02/17/2012 02:07 PM, Kevin Cox wrote: Yes. At least as the compiler would say. It's a little odd but I believe that is how the D Nam mangling works. I personally just think of Foo!(Class) as the type. class Foo(T){ ... } Is syntactic sugar for template Foo(T){ class Foo{ ... } }

Re: Let this() figure out T implicitly?

2012-02-17 Thread kraybourne
On 2/17/12 2:38 PM, Timon Gehr wrote: On 02/17/2012 02:07 PM, Kevin Cox wrote: Yes. At least as the compiler would say. It's a little odd but I believe that is how the D Nam mangling works. I personally just think of Foo!(Class) as the type. class Foo(T){ ... } Is syntactic sugar for

Re: Let this() figure out T implicitly?

2012-02-17 Thread Ali Çehreli
On 02/17/2012 09:08 AM, Steven Schveighoffer wrote: What you are asking for is IFTI (Implicit Function Template Instantiation) on constructors, and is perfectly possible, but not implemented: http://d.puremagic.com/issues/show_bug.cgi?id=6082 What was the resolution for the case when the

Re: Let this() figure out T implicitly?

2012-02-17 Thread Timon Gehr
On 02/18/2012 12:04 AM, Ali Çehreli wrote: On 02/17/2012 09:08 AM, Steven Schveighoffer wrote: What you are asking for is IFTI (Implicit Function Template Instantiation) on constructors, and is perfectly possible, but not implemented: http://d.puremagic.com/issues/show_bug.cgi?id=6082

Re: Let this() figure out T implicitly?

2012-02-17 Thread Ali Çehreli
On 02/17/2012 05:59 PM, Timon Gehr wrote: On 02/18/2012 12:04 AM, Ali Çehreli wrote: On 02/17/2012 09:08 AM, Steven Schveighoffer wrote: What you are asking for is IFTI (Implicit Function Template Instantiation) on constructors, and is perfectly possible, but not implemented:

Re: Let this() figure out T implicitly?

2012-02-17 Thread Timon Gehr
On 02/18/2012 03:22 AM, Ali Çehreli wrote: On 02/17/2012 05:59 PM, Timon Gehr wrote: On 02/18/2012 12:04 AM, Ali Çehreli wrote: On 02/17/2012 09:08 AM, Steven Schveighoffer wrote: What you are asking for is IFTI (Implicit Function Template Instantiation) on constructors, and is