mercredi 7 janvier 2015

VC++ 2013 std::move and rvalue compile error

I am following this tutorial on using C++ 11 threads.The following code :



#include <iostream>
#include <string>
#include <thread>
#include <future>

void theFun(std::promise<std::string> && prms)
{
std::string str("Hellow from future");
prms.set_value(str);
}

int main(int argc, char* argv[])
{
std::promise<std::string> prms;
std::future<std::string> ftr = prms.get_future();

std::thread tr(&theFun,std::move(prms));
std::cout << "Hellow from main!" << std::endl;
std::string str = ftr.get();//will block if thread still working

std::cout << str << std::endl;
tr.join();
}


works for the tutorial author.He is using VS2010 and some experiment implementation.But in my case I am getting the following error:



\program files (x86)\microsoft visual studio 12.0\vc\include\functional(1149): error C2664: 'void (std::promise &&)' : cannot convert argument 1 from 'std::promise' to 'std::promise &&' 1>

You cannot bind an lvalue to an rvalue reference



Does it mean VC2013 doesn't support Rvalue arguments?


Aucun commentaire:

Enregistrer un commentaire