Some more template syntax sugar

Walter Bright newshound at digitalmars.com
Tue Aug 29 01:22:19 PDT 2006


Reiner Pope wrote:
> I think function templates still require too much in the way of type 
> annotations. Take the canonical example, sqr:
> 
> T sqr(T) (T x)
> {
>     return x*x;
> }
> 
> In this example, we have to declare T three times, even though I think 
> this could be inferred. I propose an alternative syntax:
> 
> auto sqr(x)
> {
>     return x*x;
> }
> 
> which IMHO looks very elegant.

I know. The problem is that it is indistinguishable from:

	typedef int x;
	auto sqr(x);

i.e. when x is a typedef and no parameter name is given, or when x is a 
parameter name and no type is given.



More information about the Digitalmars-d mailing list