Some more template syntax sugar
Derek Parnell
derek at nomail.afraid.org
Tue Aug 29 16:11:02 PDT 2006
On Tue, 29 Aug 2006 01:22:19 -0700, Walter Bright wrote:
> 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.
Think outside the actual example and see if the concept of doing a
simplification can be achieved. I'm sure you can come up with a better
syntax for such an obvious improvement.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
30/08/2006 9:09:51 AM
More information about the Digitalmars-d
mailing list