Subject: Re: [boost] interest in generic cyclic visitor?
From: Jan Herrmann (jherrmann79_at_[hidden])
Date: 2012-08-06 12:26:05
On 03.08.2012 15:24, Larry Evans wrote:
> On 08/03/12 07:58, Sohail Somani wrote:
>> On 03/08/2012 3:17 AM, Jan Herrmann wrote:
>>> Additionally it can be used as a base for multimethod implementation.
>> This is much more interesting to me. Can you elaborate or give some
>> sample code?
> Then you might be interested in the multimethods discussion
> in a July 2010 thread:
Thank you for this link.
> As shown elsewhere in that thread, there's multimethod code available
> already in the boost sandbox. That code:
> is one example. Another, more complete example, is here:
Thank you for these links, too.
> The more complete example shows the method can be used both with virtual
> functions and discriminated unions, such as boost:: variant
> or that in:
> Unfortunately, the multimethod using the one_of_maybe discriminated
> union can be a compile-time hog (based on some simple tests I've run).
> I've no idea why :(
I have included visiting variants, too. It was really simple. I
furthermore can visiting anys and polymorphic base classes with a
wrapper. It uses any_cast or dynamic cast and works like Alexandrescus
static dispatcher. The only problem I have and which i cant solve is the
polynomial amount of code. The compiler has simply to build a lot of
classes and virtual functions for every case.
My main idea is to provide (normally) 2 templated functions for all
void accept(MyClass const&, static_visitor& sv);
void accept(MyClass & static_visitor& sv);
As long as these functions can be found you can build a const correct
multimethod implementation on top of them without knowing anything about
MyClass. Please look at
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk