Boost logo

Boost Users :

Subject: Re: [Boost-users] problems with boost bind and boost thread
From: Igor R (boost.lists_at_[hidden])
Date: 2012-03-22 10:06:57


> I have problems with the attached code (test.cpp, extracted from the
> original class only with the relevant code).
> The member template  constructor of CCycleThread takes an argument and
> passes this to boost bind. The binding is to a another member template
> method which is the thread function for boost thread:
>
> boost::thread(boost::bind(&CCycleThread::execute<T>,this,t)
>
> The template parameter type is deduced by the argument type passed by the
> user.
>
> If the type is an ordinary function the code works fine. If the argument
> itself is another boost bind object the compilation fails!

If the argument is a binder, you should wrap it with boost::protect
and specialize CCycleThread::execute accordingly:
m_thread.reset(new
boost::thread(boost::bind(&CCycleThread::execute<boost::_bi::protected_bind_t<T>
>, this, boost::protect(t))));
However, the problem is that now if a user passes a simple function
pointer, it wont compile.
Thus, you should separate the 2 cases using enable_if/disable_if, but
I can't realise right now what type trait could be useful for this
purpose...


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