Article on Tuples

xs0 xs0 at xs0.com
Thu Nov 16 08:09:09 PST 2006


Sean Kelly wrote:
> Walter Bright wrote:
>> Sean Kelly wrote:
>>> Ack! Related question :-)  I assume this will work at some point?:
>>>
>>>   T fn( T, U )( U val )
>>>   {
>>>       return T.init;
>>>   }
>>>
>>>   void main()
>>>   {
>>>       int i = fn!(int)( 1.0 );
>>>   }
>>>
>>> Currently, I get:
>>>
>>>   test.d(9): template instance fn!(int) does not match any template 
>>> declaration
>>>   test.d(9): Error: template instance 'fn!(int)' is not a variable
>>>   test.d(9): Error: function expected before (), not fn!(int) of type 
>>> int
>>
>> That's a hard one to get to work, as it has chicken-and-egg problems.
> 
> Hrm... I think that one may eventually turn out to be fairly important. 
>  It's quite common to specify only the return type for template 
> functions in C++.  The most obvious example being the cast functions.
> 
> 
> Sean

This works, though:

import std.stdio;

template foo(T)
{
	T foo(U)(U u)
	{
		writefln(u);
		return T.init;
	}
}

void main()
{
	int i = foo!(int)(1.5);
}


xs0



More information about the Digitalmars-d-announce mailing list