[Proposal] "Name inference" for function templates

Daniel Keep daniel.keep.lists at gmail.com
Fri Jun 16 00:04:21 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.

>_<  When did THAT get added?  And why didn't I notice?!

<sob>  All those extra lines of code... all that extra typing... makes
you wonder how much of D we don't actually know about :P

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list