Boost logo

Boost :

From: Peng Yu (pengyu.ut_at_[hidden])
Date: 2007-07-17 10:25:53


On 7/17/07, David Abrahams <dave_at_[hidden]> wrote:
>
> on Tue Jul 17 2007, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
>
> > On 7/16/07, Mathias Gaunard <mathias.gaunard_at_[hidden]> wrote:
> >> Peng Yu wrote:
> >>
> >> > I've seen typelist somewhere. I'm wondering if it is defined in boost?
> >>
> >> Boost has better than that, it has the Boost Meta-Programming Library
> >> (MPL) that contains various data structures and algorithms around types.
> >
> > Hi,
> >
> > I saw list in mpl. But I'm not familiar with it yet. Would you please
> > show me how to do the same thing in mpl as that in my original
> > email?
>
> typedef boost::mpl::list<Rect_, Square_, Triangle_, RightTriangle_> Shapes_;
>

Hi,

I actually meant to define a visitor class for those shapes like the
following. Is there anything similar to type_list::head and
type_list::tail in mpl::list?

In the following code, I need to "using" the visit function from the
visitor<typename TL::tail, Base>. But there is not visit function in
visitor<list_end, Base>. Do you know how make the using statement
conditional on the base visitor class?

Thanks,
Peng

class A;
class B;

typedef type_list<A, type_list<B> > AB;

class base {
 public :
   virtual ~base() {}
   virtual void accept(base& b) = 0 ;
};

template <typename TL, typename Base>
class visitor : public visitor<typename TL::tail, Base> {
 public :
   virtual ~visitor() { }
   virtual void visit(typename TL::head &) {
      std::cout << __PRETTY_FUNCTION__ << std::endl;
   }
   using visitor<typename TL::tail, Base>::visit;
// no visit() function defined for visitor<list_end, Base>
// is there any way to make the above using statement conditional?
// (if the base class is visitor<list_end, Base>, not to use this statement.)
};

template <typename Base>
class visitor<list_end, Base> : public Base {
 public :
   virtual ~visitor() { }

};


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk