[Proposal] "Name inference" for function templates

Andrei Khropov andkhropov at nospam_mtu-net.ru
Thu Jun 15 15:55:21 PDT 2006


I think retyping the same name twice for function templates is not a very
natural way, so I propose omitting the template name if there's only a single
declaration in the template's body and then this declaration's name is
"inferred " for subsequent use, i.e. :

------------------------------------------------
template sqr(T)
{
	T sqr( T x )
	{
		return x*x;
	}
}
------------------------------------------------

could be replaced by

------------------------------------------------
template(T)
{
	T sqr( T x )
	{
		return x*x;
	}
}
------------------------------------------------

The usage is as usual:

------------------------------------------
int main( char[][] args )
{
    writefln("sqr(5) returns %d", sqr(5) );
    return 0;
}
------------------------------------------

This syntax also looks familiar to C++ guys ;-).

The only obstacle I see is that it may somewhat complicate the compiler.

-- 
AKhropov



More information about the Digitalmars-d mailing list