3 ms·
You can use a tree for multiple dispatch (visitor pattern is not required, not sure why you mention that) or you can use a plain vtable approach where you take
by mlthoughts2018 6y ago
You can use a tree for multiple dispatch (visitor pattern is not required, not sure why you mention that) or you can use a plain vtable approach where you take all the function operands and place them in a tuple. The type of that tuple (as a single object) then determines the multi-operand dispatch in the vtable approach. Some languages do make it harder to construct these tuple types, but in principle vrable is fine for multiple dispatch even in eg C++.
- stabbles 6y agoSure, you can implement it yourself. But even if you create an amazing tree/hashmap-based type-signature-tuple inheritance-aware multiple dispatch object, you still have to think about how to make other packages use it. I would also be interested how you would deal with the dynamic case of type erasure in this setup. Suppose I have a base class Base and derived classes A, B, and C. There's a set of functions f(A*, B*, A*) f(C*, A*, A*) for some combinations of pointers to A, B and C. Given a std::vector<std::tuple<Base*,Base*,Base*>> how do you apply the correct f to all its values?