Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-12-29 11:16:24


Ok,

I found out why it is so. :( Unfortunately (as already stated before), mpl::map can be used with
custom pair types, but it will always return mpl::pair type and that caused in my case different
types to be used in the derivation processing.

May be you guys could consider changing the map so, that custom pair types can be used.

With Kind Regards,

Ovanes

On Fri, December 29, 2006 16:39, Ovanes Markarian wrote:
> Hi!
>
> I am trying to create a static visitor using metapgramming. This approach worked fine in some test
> code, but now I face some problems.
>
> Let me first show some example:
>
>
> I've define an item_visitor template class:
>
> template <class Pair> //mpl::pair obtained from map sequence
> struct item_visitor
> {
> public:
> typedef typename Pair::second value_type;
>
>
> virtual void visit(value_type const& t)
> {
> assert(0 && "This function must be overriden in the concrete handler class!");
> }
> };
>
>
>
> template<class Seq>
> struct base_sequence_visitor
> : public boost::mpl::inherit_linearly
> <
> Seq
> , boost::mpl::inherit<boost::mpl::_1, item_visitor<boost::mpl::_2> >
> >::type
> {};
>
>
> This example works fine and I can dispatch my type.
>
> Now I have some additional type, which provides a view to my structure. And I would like my visit
> to implemented as:
>
> virtual void visit(GenericView<Pair::second> const& t)
> { ... }
>
> In such a case I have to introduce a second parameter to the item_visitor template:
>
> template<class Pair, template<class> SomeView>
> struct item_visitor { ... };
>
>
> Therefore the base_sequence_visitor must be updated as well to forward the View template:
>
> template<class Seq, template<class> SomeView>
> struct base_sequence_visitor
> : public boost::mpl::inherit_linearly
> <
> Seq
> , boost::mpl::inherit<boost::mpl::_1, item_visitor<boost::mpl::_2, SomeView> >
> >::type
> {};
>
>
> Using this construct I get an error, that mpl::arg<2> does not have a type second. That means that
> the placeholder _2 does not get expanded. So I tried to "code around" and used the following
> trick:
>
> template<class>
> calss SomeView;
>
> template<class Pair>
> struct some_visitor : item_visitor<Pair, SomeView>
> {};
>
> Then I added to the base_sequence_visitor template an additional argument, which specifies an item
> visitor class to be used:
>
> template<class Seq, template<class> ItemVisitor>
> struct base_sequence_visitor
> : public boost::mpl::inherit_linearly
> <
> Seq
> , boost::mpl::inherit<boost::mpl::_1, ItemVisitor<boost::mpl::_2> >
> >::type
> {};
>
> And it compiles fine! But when I try to cast the base_sequence_visitor to some complete
> item_visitor type, which is really in the sequence I receive a compiler error, that
> cannot convert from 'base_sequence_visitor<Seq,ItemVisitor>' to
> 'ClassWhereSimpleVisitorIsDefined::simple_visitor<PairType> &'
>
> Do I miss something?
>
>
> With Kind Regards,
>
> Ovanes Markarian
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net