[英]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 :: 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. VC ++ 2012由于互斥锁上的私有副本构造函数而无法编译。 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. 在我看来,所有内容都在参考中,因此没有副本。
You are trying to copy queue
by passing it by value to the std::thread
constructor. 您正在尝试通过按值将queue
传递给std::thread
构造函数来复制queue
。 If you mean to pass a reference, use a wrapper: std::ref(queue)
. 如果要传递引用,请使用包装器: std::ref(queue)
。
If you really want to move queue
into the std::thread
, you need to pass std::move(queue)
to make it an rvalue. 如果您真的想将queue
移入std::thread
,则需要传递std::move(queue)
使其成为右值。 It still won't work though, because of a bug in VS . 但是由于VS中的错误,它仍然无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.