[Proposal]

Sean Fritz Sean_member at pathlink.com
Fri Jun 16 06:21:58 PDT 2006


In article <e6u86a$226k$1 at digitaldaemon.com>, Frits van Bommel says...
>
>Andrei Khropov wrote:
>> ------------------------------------------------
>> template(T)
>> {
>> 	T sqr( T x )
>> 	{
>> 		return x*x;
>> 	}
>> }
>> ------------------------------------------------
>[snip]
>> 
>> This syntax also looks familiar to C++ guys ;-).
>
>If you're going in that direction, you might want to also make the outer 
>braces optional in this case, as they don't really add anything.
>
>template(T) T sqr( T x )
>{
>	return x*x;
>}
>
>I think this would look cleaner, as well as even *more* familiar to 
>people used to C++.

I dislike like this as it explicitly introduces the template parameter throught
the redundant word "template" (this is one of my dislikes of C++ templates - the
massive code bloat they introduce).  The current syntax:

> T sqr(T) ( T x )
> {
>     return x*x;
> }

Is the way Java Generics do it, and there is no problem parsing it, as it also
explicitly introduces T, but there may be arguments made that sqr(T)(T x) is
harder to read because it depends on context instead of explicit declaration.
The context is a bit harder to notice in this case due to using () as template
delimiters instead of &lt; &gt;.

Sean





More information about the Digitalmars-d mailing list