Boost logo

Boost :

From: Itay (itay_maman_at_[hidden])
Date: 2002-07-03 06:56:44

"Mac Murrett" <mmurrett_at_[hidden]> wrote in message
> I have been looking at the implementations of variant classes
> floating by here, and while I have been happy with aspects of them,
> I am not happy with the visitability of any of them.
Could you elaborate on that?

> I therefore
> set out to provide an ideal visitor base class, based on some
> previous work of mine: it should be templatized on a type list (no
> holy wars on what type of type list, please :) ), should provide an
> interface consisting of a visit function for each type in the type
> list (that takes a reference to the type), and should have a
> pure-virtual back-end. The trick is to have the public interface
> be nonvirtual to avoid hidden virtual function problems.
> The implementation (with an example) is available at
> As it uses
> type lists, it requires MPL. It has been verified on CW 7.2, CW 8,
> and GCC 3.1. It *does not* work won GCC 2.95.2.
> Comments appreciated,
> Mac Murrett.
The main disadvantage of this implementation - when compared to the visitor
in the suggested variants implementations -
is that it is too strict. You must supply an appropriate visit_impl member
function for each type on the type-list. This increases
code duplication, since its very likely that you can handle several types by
one function. To clarify this point, here is a concrete visitor
which, I think, cannot work with your suggested boost::visitor:

struct inc_by_10_visitor : visitor<int, short, unsigned int, char>
    void visit_impl(int x)
        cout << "result = " << x+10 << endl;



Boost list run by bdawes at, gregod at, cpdaniel at, john at