I was reading about std::for_each
in cppreference:
与其余并行算法不同,不允许for_each 即使序列中的元素琐碎,也要对其进行复制 可复制的。
So, to me, it means that std::for_each
does not copy-construct objects in the container and it should work fine with a container of non-copyable objects. But while trying to compile this code with VS2015:
std::vector<std::thread> threads;
std::for_each(
threads.begin(),
threads.end(),
[threads](std::thread & t) {t.join(); });
编译器抱怨要删除的cctor:
Error C2280 'std::thread::thread(const std::thread &)': attempting to reference a deleted function ...
我对上述报价的理解有什么问题?