Is type list defined in boost

Hi, I've seen typelist somewhere. I'm wondering if it is defined in boost? Thanks, Peng struct ListEnd_ {}; template< typename THead, typename TTail = ListEnd_ > struct TypeList_ { typedef THead item; typedef TTail next; }; class Rect_; class Square_; class Triangle_; class RightTriangle_; typedef TypeList_< Rect_, TypeList_< Square_, TypeList_< Triangle_, TypeList_< RightTriangle_ > > > > Shapes_;

On 7/16/07, Mathias Gaunard <mathias.gaunard@etu.u-bordeaux1.fr> 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? Thanks, Peng

On 7/17/07, Peng Yu <pengyu.ut@gmail.com> wrote:
On 7/16/07, Mathias Gaunard <mathias.gaunard@etu.u-bordeaux1.fr> 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?
Hi, I forgot mention that I use type_list in the following code. I'm wondering how to replace type_list with mpl::list. 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() { } };

on Tue Jul 17 2007, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
On 7/16/07, Mathias Gaunard <mathias.gaunard@etu.u-bordeaux1.fr> 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_; See http://www.boost-consulting.com/mplbook -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com

On 7/17/07, David Abrahams <dave@boost-consulting.com> wrote:
on Tue Jul 17 2007, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
On 7/16/07, Mathias Gaunard <mathias.gaunard@etu.u-bordeaux1.fr> 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() { } };

on Tue Jul 17 2007, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
On 7/17/07, David Abrahams <dave@boost-consulting.com> wrote:
on Tue Jul 17 2007, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
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?
Well, there is, but in general you don't do it that way. You'd want to write code that works just as well with typedef boost::mpl::vector<Rect_, Square_, Triangle_, RightTriangle_> Shapes_; All those virtual functions are a waste of time; none of them override the others. AFAICT all you're really trying to do is generate an overload set on the elements of Shapes_. struct base_visitor { void visit(); }; template <class T, class Base> struct visitor : Base { void visit(T&) { /*...*/ } using Base::visit; }; typedef mpl::fold<Shapes_, base_visitor, visitor<_2,_1> >::type v; HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com

On 7/17/07, David Abrahams <dave@boost-consulting.com> wrote:
on Tue Jul 17 2007, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
On 7/17/07, David Abrahams <dave@boost-consulting.com> wrote:
on Tue Jul 17 2007, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
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?
Well, there is, but in general you don't do it that way. You'd want to write code that works just as well with
typedef boost::mpl::vector<Rect_, Square_, Triangle_, RightTriangle_> Shapes_;
All those virtual functions are a waste of time; none of them override the others. AFAICT all you're really trying to do is generate an overload set on the elements of Shapes_.
struct base_visitor { void visit(); };
template <class T, class Base> struct visitor : Base { void visit(T&) { /*...*/ } using Base::visit; };
typedef mpl::fold<Shapes_, base_visitor, visitor<_2,_1> >::type v;
I know _2 and _1 are placeholders. But I'm not very clear how they are used here. I tried to read the manual for "fold", but its explanation refers to many other mpl structs. Could you give me some easy explanation on how this works? Thanks, Peng

on Tue Jul 17 2007, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
I know _2 and _1 are placeholders. But I'm not very clear how they are used here. I tried to read the manual for "fold", but its explanation refers to many other mpl structs.
Could you give me some easy explanation on how this works?
Sorry, not much time today. I suggest that you read the book ;-) <http://www.boost-consulting.com/mplbook> Maybe this much will help: fold<...> is also known as accumulate<...>. See your friendly STL manual. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com
participants (3)
-
David Abrahams
-
Mathias Gaunard
-
Peng Yu