Let this() figure out T implicitly?

Steven Schveighoffer schveiguy at yahoo.com
Fri Feb 17 09:08:27 PST 2012


On Fri, 17 Feb 2012 07:19:28 -0500, kraybourne <stdin at kraybourne.com>  
wrote:

> 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);
> 	}
> 	_____
>
> 	$ dmd foo
> 	foo.d(13): Error: class foo.Foo(T) is used as a type
> 	$ _
>
> So I must
>
> 	auto o = new Foo!(int)(5);
>
> Then it compiles. Is it possible to have this() figure out the type some  
> way? (In this particular example it's perhaps not such a big deal. But  
> imagine a lot more args.)

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

Vote up if you want to see it happen!

-Steve


More information about the Digitalmars-d-learn mailing list