仅移动类型的back_inserter
back_inserter for move-only type
在下面的代码中,对象'queue'是不可复制的,但由于std::互斥,它是可移动的。
std::generate_n(std::back_inserter(thread_pool),
std::thread::hardware_concurrency,
[&](){return std::thread(handler(), exiting, queue);});
VC++2012无法编译,因为互斥对象上有一个私有副本构造函数。它无法为队列生成复制构造函数。为什么会有任何东西试图复制队列?在我看来,一切都是参考的,因此没有副本。
您正试图通过将值传递给std::thread
构造函数来复制queue
。如果要传递引用,请使用包装器:std::ref(queue)
。
如果您真的想将queue
移动到std::thread
中,则需要传递std::move(queue)
使其成为右值。不过,由于VS中的一个错误,它仍然无法工作。
相关文章:
- 推导 std::vector::back() 的返回类型
- vector.back() 和 vector[vector.size() - 1] 之间的区别?
- vector.push_back(vector.back()+1) 是未定义的行为吗?
- 线路抑制状态错误 C4703 可能未初始化的局部指针变量"back"已使用
- std::vector using back(), pop_back(), push_back(), 得到'double free or corruption'错误
- C++ STL-Inserter
- vector.back()和vector.end()有什么区别
- 列表大小为 1,但 front() 和 back() 不相等
- 返回C++中没有 back() 方法的容器的最后一个元素?
- 在非空 std::list 上使用 std::list.back<int>() 时"Segmentation Fault"
- 我们可以使用Back() - 值索引在其上执行向量插入
- 当我运行以下代码添加str.front() str.back时,它给了我200个,但为什么
- 链表回推操作中需要'back pointer'
- 为什么 std::string 的 back() 应该返回对字符的引用?
- VC++ 自动说明符假定矢量的引用限定符<bool>::back的引用限定符
- C: strtok value gives back null
- vector.back() 可以用来为向量的最后一个元素赋值吗?
- 在std::vector中实现back()
- 在push_front属性上有点混淆.intlist.push_front(2 * intlist.back())会做些
- 将对象转换为 char,然后"uncasting it back"