[Proposal] "Name inference" for function templates
Markus Dangl
danglm at in.tum.de
Thu Jun 15 19:35:57 PDT 2006
Andrei Khropov schrieb:
> 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;
> }
> }
> ------------------------------------------------
http://www.digitalmars.com/d/template.html
If there's only a single declaration, you can even write:
T sqr(T) ( T x )
{
return x*x;
}
Which is already in the language and even shorter than your proposal ;)
This is the same for class templates.
More information about the Digitalmars-d
mailing list