On 3 September 2016 at 22:24, Andrei Alexandrescu via Digitalmars-d <digitalmars-d@puremagic.com> wrote: > On 9/3/16 7:29 AM, Manu via Digitalmars-d wrote: >> >> On 3 September 2016 at 11:38, Andrei Alexandrescu via Digitalmars-d >> <digitalmars-d@puremagic.com> wrote: >>> >>> On 9/3/16 2:41 AM, Manu via Digitalmars-d wrote: >>>> >>>> >>>> On 3 September 2016 at 00:18, Xinok via Digitalmars-d >>>> <digitalmars-d@puremagic.com> wrote: >>>>> >>>>> >>>>> >>>>> In the past, I have suggested using the "default" keyword to specify a >>>>> fallback function of this kind. I think it's a useful pattern for >>>>> generic >>>>> algorithms that have optimized variants on specific types for >>>>> performance. >>>>> >>>>> void f(T)(T t) if(isSomething!T) {} >>>>> void f(T)(T t) if(isSomethingElse!T) {} >>>>> void f(T)(T t) default {} >>>> >>>> >>>> >>>> It's an interesting idea... flesh out a DIP? >>> >>> >>> >>> We're better off without that. -- Andrei >> >> >> Then we need a decent way to do this. > > > Use static if inside the function. The entire notion of "call this function > if you can't find something somewhere that works" is questionable. -- Andrei
It's all about: generic function 'lerp()' exists... user supplies new type, user extends standard named function 'lerp()' for their new type. We do this sort of things a lot. Consider std.conv.to?