Subject: Re: [boost] Boost.Multimethod proposal
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2009-08-23 07:53:21
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.
Multimethods could be useful for various dynamic dispatch purposes. For
instance, in Boost.Log I had to invent a similar mechanism to dispatch
attribute values in other consuming components, like filters or
formatters. Naturally, the attribute value types and types of filters
and formatters are known only in run time.
What I came up with was a double virtual call scheme, but that required
quite an amount of scaffolding already. If I had to dispatch between
three entities or more, this would get unbearable.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk