[Proposal] "Name inference" for function templates

Chris Nicholson-Sauls ibisbasenji at gmail.com
Fri Jun 16 00:45:19 PDT 2006


Markus Dangl wrote:
> 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.

I know for a definite fact this /did not work/ previously... must be something that 
happened fairly recently.  A silent enhancement, perhaps just for testing purposes for 
now?  If I can get a clear from Walter that this is a permanent feature, I am *so* taking 
advantage of it!

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list