Template functions, can we make it more simple?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Aug 2 18:15:50 PDT 2013


On 2013-08-03 00:51:19 +0000, F i L said:

> I've brought this up on here awhile ago, and many people seemed to be 
> against it. Which I don't agree with, since the ambiguities it creates 
> are easily addressed (from a design perspective at least) and only 
> exist so that C-style code is usable within D. It could work like:
> 
>     auto func(a, b)     // auto func(A, B)(A a, B b)
>     auto func(int a, b) // auto func(B)(int a, B b)
>     auto func(int ?)    // C-style: auto func(int)
> 
> Or...
> 
>     auto func(auto a, auto b) // like C++14
> 
> I mean honestly, who's hand-writing a bunch of functions with nameless 
> params in real D code? Sure it's used for linking to C, which is 
> semi-common, but I think having the much cleaner syntax available to 
> "actual" D code makes more sense that not having it solely for 
> linking-to-C-in-familiar-C-style reasons.

The converse question is who's hand-writing a bunch of functions that 
don't need their arguments' types in any way (for constraints or 
otherwise). There are very few functions that really apply to all 
types. It's possible that by allowing auto parameter types we encourage 
a sloppy style.

Andrei



More information about the Digitalmars-d mailing list