$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: David Abrahams (dave_at_[hidden])
Date: 2006-01-17 10:58:01
David Greene <greened_at_[hidden]> writes:
> I'm trying something new using mpl's inherit_linearly but I can't
> figure out how to do what I want to do.
>
> The idea, simply:
>
> template<typename Policies>
> class Test : public inherit_linearly<Policies, inherit<_1, _2> >::type {
> public:
>    void do_something(void) {
>       for each Base in Policies
>          Base::do_something();
>       rof
>    }
> };
>
> Is there a straightforward way to do this or am I thinking about this
> in the wrong way?
See mpl::for_each:
  template<typename Policies>
  class Test 
    : public inherit_linearly<Policies, inherit<_1, _2> >::type 
  {
      struct do_it
      {
          template <class B>
          void operator()(Test* self, B*) const
          {
              self->Base::do_something();
          };
      };
  public:
     void do_something(void)
     {
         mpl::for_each<
             Policies
           , boost::add_pointer<mpl::_> 
         >(
              boost::bind(do_it(), this, _1) 
         );
     }
  };
http://www.boost-consulting.com/mplbook covers this topic.
-- Dave Abrahams Boost Consulting www.boost-consulting.com