Template functions, can we make it more simple?

John Colvin john.loughran.colvin at gmail.com
Sat Aug 3 04:14:18 PDT 2013


On Saturday, 3 August 2013 at 01:15:48 UTC, Andrei Alexandrescu 
wrote:
> 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

The existence of template restrictions and the swathes of 
different things in std.traits and elsewhere really persuaded me 
to think about the requirements of my templates. Having to spell 
it out a bit is a good thing.
In short: I agree.


More information about the Digitalmars-d mailing list