This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Promise, future and thread on C++0x


Hello!
I try this program on Linux Ubuntu and GCC(G++) 4.5.2 that use Promise and
Future

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

using namespace std;


void myAsyncFun(promise<int> intPromise)
{
int result;
try {
// calculate the result
result = 25;
intPromise.set_value(result);
}
catch (std::exception& e)
{
intPromise.set_exception(std::copy_exception(e));
}
}


int main()
{
promise<int> intPromise;
future<int> intFuture = intPromise.get_future();
std::thread t(myAsyncFun, std::move(intPromise));
// do some other stuff
int result = intFuture.get(); // may throw MyException
cout<<"Result from thread: "<<result<<endl;
return 0;
}

I get a compiler error:

/usr/include/c++/4.5/future|855|error: deleted function
âstd:promise<_Res>:promise(const std:promise<_Res>&) [with _Res = int,
std:promise<_Res> = std:promise<int>]â|

/usr/include/c++/4.5/thread|141|error: used here|

/usr/include/c++/4.5/thread|141|error: initializing argument 2 of
âstd::_Bind<typename std::_Maybe_wrap_member_pointer<_Tp>::type(_ArgTypes
...)> std::bind(_Functor, _ArgTypes ...) [with _Functor = void
(*)(std:promise<int>), _ArgTypes = {std:romise<int>}, typename
std::_Maybe_wrap_member_pointer<_Tp>::type = void (*)(std:promise<int>)]â|


Why?
-- 
View this message in context: http://old.nabble.com/Promise%2C-future-and-thread-on-C%2B%2B0x-tp32008761p32008761.html
Sent from the gcc - libstdc++ mailing list archive at Nabble.com.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]