2
我得到的錯誤說下面的fill_n
行試圖使用刪除的複製構造函數:爲什麼它不試圖使用移動構造函數?我試圖把它包裝在std::move
中,但這沒有幫助。爲什麼沒有在fill_n中調用移動構造函數
std::vector<std::thread> workers;
workers.reserve(10);
std::fill_n(std::back_inserter(workers), 10, std::thread([]{ std::cout << "thread\n"; }));
但是,如果我改變fill_n
線
for(int i = 0; i < 10; ++i)
{
workers.push_back(std::thread([]{ std::cout << "thread\n"; }));
}
工作正常。我認爲這些基本上和我之前在一些類似的代碼中做過的改變一樣。