Boost logo

Boost Users :

Subject: Re: [Boost-users] [MPL] for_each help needed
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-10-06 11:38:01


AMDG

Manuel Jung wrote:
> Hey,
>
> I have problems using mpl::for_each. Well, it works for simple functors, but
> i need a functor with some context. I'm trying to build a functor through
> boost::bind. mpl::_1 should be a type from the consensus sequence if
> evaluated, shouldn't it? You can see a small (hopefully not too small)
> example below.
>

mpl::_1 is not expanded by Boost.Bind. You need something like

template<class T>
struct wrap {};

struct connect_f {
    typedef void result_type;
    template<class Producer, class Self, class T>
    void operator()(Producer* producer, Self* self, const wrap<T>&) const {
        producer->connect(self->get_promise<T>());
    }
};

...

boost::mpl::for_each<consensus, wrap<mpl::_1> >(boost::bind(connect_f,
&Producer, this, _1));

In Christ,
Steven Watanabe


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