Friday, 9 August 2013

back_inserter for move-only type

back_inserter for move-only type

In the following code the object 'queue' is non-copyable, but is movable
due to a std::mutex.
std::generate_n(std::back_inserter(thread_pool),
std::thread::hardware_concurrency,
[&](){return std::thread(handler(), exiting, queue);});
VC++2012 is failing to compile due to a private copy constructor on the
mutex. It is failing to generate the copy constructor for queue. Why would
anything be trying to copy queue? It appears to me that everything is
taking it by reference, thus no copies.

No comments:

Post a Comment