Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.72 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. C   - Boost.Promise, Boost.Unique_Future and Move Semantics
  2. #include <iostream>
  3. #include <cassert>
  4. #include <boostthread.hpp>
  5. #include <boostthreadfuture.hpp>
  6.  
  7. void thFun(boost::promise<std::string> & prms)
  8. {
  9.     std::string str("Hi from future!");
  10.     prms.set_value(str);
  11. }
  12.  
  13. int main()
  14. {
  15.     boost::promise<std::string> prms;
  16.     boost::unique_future<std::string> fut = prms.get_future();
  17.  
  18.     boost::thread th(&thFun, std::move(prms)); // error C2248: 'boost::promise<R>::promise' : cannot access private member declared in class 'boost::promise<R>'
  19.  
  20.     std::cout << "Hi from main!";
  21.     std::string str = fut.get();
  22.     std::cout << str << std::endl;
  23.     th.join();
  24.  
  25.     return 0;
  26. }
  27.        
  28. boost::thread th(&thFun, std::move(prms));