Fallback 'catch-all' template functions

Manu via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 1 04:20:31 PDT 2016


On 1 September 2016 at 20:43, Dominikus Dittes Scherkl via
Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> On Thursday, 1 September 2016 at 05:37:50 UTC, Manu wrote:
>>
>> Consider that more overloads are being introduced by users spread out
>> across many modules that define their own kind of T; this solution is no
>> good.
>
>
> Simply
> void f(T)(T t)
> {
>    static if(isSomething!T)
>    {
>    }
>    else static if(isSomethingElse!T)
>    {
>    }
>    else
>    {
>    }
> }
>
> I personally hate overloads, especially if the condition has a fallback, so
> I like to see no condition in the function signature, what makes for a much
> cleaner API.
> I have never seen what benefit could be gained from having overloads. I
> think they are a relict from languages without static if.

I think you must have not read the line of text that you replied to...


More information about the Digitalmars-d mailing list