以下のプログラムをコンパイルできません。std :: moveがstd :: listと一緒に動作しない理由
void toSin(std::list<double>&& list)
{
std::for_each(list.begin(), list.end(), [](double& x)
{
x = sin(x);
});
}
int main()
{
std::list<double> list;
const double pi = 3.141592;
const double epsilon = 0.0000001;
for (double x = 0.0; x < 2 * pi + epsilon; x = x + pi/16)
{
list.push_back(x);
}
// Start thread
std::thread th(toSin, std::move(list));
th.join();
return 0;
}
私は>エラーC2664取得: 'void (std::list<double,std::allocator<_Ty>> &&)
':あなたのコンパイラがここに間違っているように私は感じる 'std::list<double,std::allocator<_Ty>> &&
'
再現私はできません。どのバージョンのVisual Studioを使用していますか?あなたに気をつけて、私は一杯の紛失したヘッダーを追加しました。 – user4581301
'std :: thread th(toSin、std :: move(list));'行は、移動しているので、その点を越えて 'list'を反復してはならないことを意味します。しかし、あなたはそれを次の行で繰り返そうとします。 –
Visual Studio 2013 –