Overloading free functions & run-time dispatch based on parameter types

Robert M. Münch via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 7 05:47:12 PST 2016


On 2016-02-06 14:33:57 +0000, Marc Schütz said:

> I don't see why this wouldn't work, if you've in fact covered all combinations.

It works, the problem was that castSwitch returns something and I 
didn't "catch" it.

> It's similar to how castSwitch is implemented, though the double casts 
> are inefficient. You could use:
> 
> if(auto inta = cast(IntV) a) {
>      if(auto intb = cast(IntV) b) {
>          return new IntV(inta.num + intb.num);
>      }
> }

Yes, thanks. Was on my list.

> (Again, this can be automated.)

How? Do you mean by castSwitch?


>> I read this here: 
>> https://github.com/D-Programming-Language/phobos/pull/1266#issuecomment-53507509 
>> (functional pattern matching) but it seems it won't be implemented... 
>> at the end of the day what I simulate are poor-mans-multimethods
> 
> As I read the discussion, it was just decided to defer the more complex 
> version of castSwitch for later, but it wasn't rejected.

Well... yes, "won't be implemented in the near future" Anyway, it's not 
available at the moment, so looking at other ways.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20160207/6312429f/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list