UFCS for templates

Ary Borenszweig ary at esperanto.org.ar
Fri Aug 9 05:22:52 PDT 2013


On 8/8/13 2:55 PM, Dicebot wrote:
> On Thursday, 8 August 2013 at 17:35:02 UTC, JS wrote:
>> Can we have UFCS for templates?
>>
>> e.g.,
>>
>> T New(T, A...)(A args) { }
>>
>>
>> T t = T.New(args);
>>
>>
>> Note, in this case, the type parameter is substituted.
>
> As always, providing motivating use case and advantage/cost comparison
> is usual requirement to make something happen.
>
> DIP's exist for a reason.

Come on, in this case I don't think he needs to provide a motivating use 
case.

What's the motivating use case for UFCS in the first place? You can live 
without it just fine, only the syntax is uglier. Being able to call a 
function "foo" whose first argument is of type T as T.foo is nice and 
uniform.

Not having the same for templates is *not* uniform, and code tends to 
get uglier.

That's his use case.

However, it might slow down compilation times because now you have to 
look for every possible template and see if the first argument matches 
that of the "receiver" of the method (but maybe that's how UFCS is done 
in the first place?).


More information about the Digitalmars-d mailing list