Template functions, can we make it more simple?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Aug 2 15:19:33 PDT 2013


On 8/2/13 3:17 PM, Timon Gehr wrote:
> On 08/03/2013 12:06 AM, Andrej Mitrovic wrote:
>> On 8/2/13, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
>>> auto fun(auto x, auto y) { … }
>>>
>>> Truth be told, at the time of that decision
>>> parameter names (viz. x and y) could not be used in template
>>> constraints. Now they could, so in a way that reopens the question.
>>
>> You'd still have to use typeof(x) and typeof(y) to extract the types,
>> so even though you end up making the template declaration simpler you
>> also make the constraint more complicated.
>> ...
>
> bool compare(a,b) if(__traits(compiles,a<b)) { return a<b; }

Direct use of __traits is unrecommended outside the stdlib. I had this 
pattern in mind:

bool compare(auto a, auto b) if (is(typeof(a < b) : bool)) { ... }


Andrei



More information about the Digitalmars-d mailing list