interest in generic cyclic visitor?

Hello, I have an implementation of generic cyclic visitor. It is available at https://github.com/janherrmann/visitor . With my implementation it is possible to create non-member, non-friend templates which behave like virtual functions. Additionally it can be used as a base for multimethod implementation. Moreover it can be used to build a extensible type information system. All test cases compile with msvc-10.0 and gcc-mingw-4.6.2. Is there need for such a library? Jan Herrmann

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: http://thread.gmane.org/gmane.comp.lib.boost.devel/206203 As shown elsewhere in that thread, there's multimethod code available already in the boost sandbox. That code: http://svn.boost.org/svn/boost/sandbox/variadic_templates/libs/composite_sto... is one example. Another, more complete example, is here: http://svn.boost.org/svn/boost/sandbox/variadic_templates/libs/composite_sto... The more complete example shows the method can be used both with virtual functions and discriminated unions, such as boost:: variant or that in: http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/composite_st... 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 :( HTH. -Larry

On 03/08/2012 10:24 AM, Larry Evans 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:
Thanks!

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:
http://thread.gmane.org/gmane.comp.lib.boost.devel/206203 Thank you for this link.
As shown elsewhere in that thread, there's multimethod code available already in the boost sandbox. That code:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/libs/composite_sto...
is one example. Another, more complete example, is here:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/libs/composite_sto... 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:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/composite_st...
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
On 03.08.2012 15:24, Larry Evans wrote: polynomial amount of code. The compiler has simply to build a lot of classes and virtual functions for every case.
HTH.
-Larry
My main idea is to provide (normally) 2 templated functions for all visitable types: template<class static_visitor> void accept(MyClass const&, static_visitor& sv); template<class static_visitor> 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 https://raw.github.com/janherrmann/visitor/master/dispatch.hpp . Best regards Jan Herrmann

On 03.08.2012 13: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?
Here is an example. In contrast to other examples I prefer hiding visitor objects in normal functions to place them in different translation units and make them easier to use. The main aspect of my multimethod (and visitor) implementation is the forwarding to a non polymorphic function object preserving the constness of its arguments. It can be templated and you can use all aspects of static polymorphism for implementing operator(). At compile time it generates a polynomial amount of code to forward to the user specified function object (for this example 3 polymorphic classes, 3 intermediate static visitors and in sum 6 virtual functions). The dispatch actually needs 2 virtual calls per polymorphic parameter (in this example 4 calls). It will detect all ambiguities at compile time and if you add new classes to a hierarchy you have to recompile everything. Depending on your static visitors (function objects) it will use base classes, a generic solution or compilation will fail. Please be aware that my intention for my library was an generic implementation of an GoF visitor. The multimethod implementation was not my primary concern but at this time it is implemented within 65 lines of (yet undocumented) code. My multimethod implementation needs only a special templated accept function which can be implemented for cyclic visitable classes, boost::variant, an wrapper for boost::any and other types with polymorphic behavior. If there is interest in my library I will implement a more generic way of using these visitors. Additional to the dispatching mechanism it will handle parameter and return value transportation. Jan Herrmann
participants (3)
-
Jan Herrmann
-
Larry Evans
-
Sohail Somani