Boost logo

Boost :

Subject: Re: [boost] Boost.Multimethod proposal
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-08-24 15:31:53


Edward Diener wrote:
> Jeffrey Bosboom wrote:
> > Edward Diener wrote:
> >> What is a practical use for multi-methods ?
> >
> > Multimethods (assuming this library uses the term as it's commonly
> > understood) are like virtual functions that are dispatched on the
> > dynamic types of their arguments as well as the type of *this. You can
> > get this effect through double dispatch, but it requires a bit of
> > plumbing and requires two virtual calls (which for some people is a
> > large amount of overhead). (Of course, multimethods have overhead too.)
>
> This does not explain the practical purpose of multimethods.
> I know what virtual functions are, of course. What in multimethods
> improves on the polymorphic capabilities of virtual functions that make them
> a practical choice for use over normal polymorphism.

If it isn't obvious yet, you missed the bit about dispatching on the *dynamic type of the arguments*. Virtual functions can dispatch on the dynamic type of this, but not on the arguments. Double dispatch uses two virtual calls to dispatch on this and then, by switching argument order, on the dynamic type of the argument-cum-this-type. Extending that beyond two types, however, becomes nearly untenable.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk