Fallback 'catch-all' template functions

Cauterite via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 1 04:25:14 PDT 2016

On Thursday, 1 September 2016 at 10:50:18 UTC, Dominikus Dittes 
Scherkl wrote:
> On Thursday, 1 September 2016 at 10:43:50 UTC, Dominikus Dittes 
> Scherkl wrote:
>> I have never seen what benefit could be gained from having 
>> overloads. I think they are a relict from languages without 
>> static if.
> I mean, overloads with same function signature except for the 
> condition. Of course if the overloads have different parameters 
> or return type, they may make sense. But they still uglyfy the 
> API, so I try to avoid them - instead I use default parameters 
> and template parameters what pretty much always works.

When you're specialising on type classes rather than concrete 
types, you have no choice:

auto f(T)(T source) if (is(ElementType!T : int)) {...};
auto f(T)(T source) if (is(ElementType!T : Object)) {...};

There is nothing you can write in the template parameters list to 
enable the same kind of specialisation.

More information about the Digitalmars-d mailing list