Boost logo

Boost :

Subject: [boost] [thread] using Boost.Thread with move-only arguments
From: Fernando Pelliccioni (fpelliccioni_at_[hidden])
Date: 2013-04-03 22:40:35

Hi Vicente,

I have an issue with Boost.Thread contructor using move-only type arguments.

The "Thread Constructor with arguments" section of the documentation says

template <class F,class A1,class A2,...>
thread(F f,A1 a1,A2 a2,...);

F and each An must by copyable or movable.

"An" could be copyable or movable, but the following example fails to

error: use of deleted function 'A::A(const A&)'

//Begin code ------------------------------------
#include <boost/thread.hpp>

struct A
    A() = default;
    A( const A& other) = delete;
    A& operator=( const A& other) = delete;
    A( A&& other) = default;
    A& operator=( A&& other) = default;

    void run() {}

void f( A a )

void exec_boost()
    A a;
    boost::thread t( f, std::move(a) );

//End code --------------------------------------

I think we should modify ...

    template <class F,class A1>
    thread(F f,A1 a1,typename
disable_if<boost::thread_detail::is_convertible<F&,thread_attributes >,
dummy* >::type=0):

... by ...

    template <class F,class A1>
    thread(F&& f,A1&& a1,typename
disable_if<boost::thread_detail::is_convertible<F&,thread_attributes >,
dummy* >::type=0):


( In the all family of related ctors in "boost/thread/detail/thread.hpp" )

But, I don't know if boost::bind is forwarding its arguments
I think we should modify Boost.Bind to be similar to std::bind.
Is there any reason why Bind has not changed so far? Have you found any

If Bind can not be changed, I think Boost.Thread should use some other tool
similar to Bind to make forwarding parameters.
GCC Libstdc++ use a Bind-lite tool for std::thread.

I can work on this if you want.
What do you think?

Windows 7 64bits
MinGW - GCC 4.7.2
MSVC 2010
MSVC 2012
Boost 1.53.0
Non-Variadic template code branch

Fernando Pelliccioni

Boost list run by bdawes at, gregod at, cpdaniel at, john at