Template functions, can we make it more simple?

Walter Bright newshound2 at digitalmars.com
Fri Aug 2 16:30:13 PDT 2013


On 8/2/2013 1:34 PM, SteveGuo wrote:
> I'm not an expert on programming language, if I made a naive issue, just forgive
> me:p

We never forgive, and the internet never forgets! :-)


> Can we declare a template function like this?
>
> auto Add(a, b) // Note a, b do not have type, that means a and b use template type
> {
>      return a + b;
> }
>
> auto Sub(a, int b) // a uses template type, b is fixed to int
> {
>      return a - b;
> }

The trouble with this is that sometimes people will use a type without an 
identifier in order to indicate that the parameter is not used:

auto Foo(int, unsigned x)

But also note that for lambdas, D does allow the form you suggest, as there 
weren't backwards compatibility issues with it.



More information about the Digitalmars-d mailing list