Boost logo

Boost Users :

Subject: Re: [Boost-users] Example program that fails to compile (boost::bind and boost::function called for collection)
From: Archie14 (admin_at_[hidden])
Date: 2009-01-27 20:16:17


Steven Watanabe <watanabesj <at> gmail.com> writes:

>
> AMDG
>
> Archie14 wrote:
> > delegate dosomething;
> > Test(CLIENTS& val) : m_clients(val) {}
> > void run()
> > {
> > std::for_each(m_clients().begin(), m_clients().end(),
> > boost::bind(&CLIENTS::CLIENT::commandhandler,
> > boost::ref(dosomething), _1 ));
> > }
> > };
> >
>
> The parameters to boost::bind are in the wrong order.
>
> Try:
>
> boost::bind(&CLIENTS::CLIENT::commandhandler,
> _1, boost::ref(dosomething)));
>
> In Christ,
> Steven Watanabe
>

Steven,

Thank you very much for the help. I have a follow-up question regarding
boost::bind. Specifically - how can I bind one boost::function to another? Here
is the short example that fails to compile:

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/ptr_container/ptr_vector.hpp>

typedef boost::function<void (int, int, const char*) > delegateOne;
typedef boost::function<void (int, const char*) > delegateTwo;

class A : public boost::noncopyable
{
public:
        void commandhandler(delegateOne& f) {
// I want to replace first argument in "delegateOne" with value 100.
                delegateTwo two = boost::bind(&f, 100, _2, _3);
        }
};

int _tmain(int argc, _TCHAR* argv[])
{
        A a;
        delegateOne t;
        a.commandhandler(t);
}


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