fork download
  1. #include <future>
  2. #include <functional>
  3. #include <type_traits>
  4. #include <iostream>
  5.  
  6. void foo()
  7. {
  8. std::cout<<"Hello, world!"<<std::endl;
  9. }
  10.  
  11. template<typename T> struct adv {
  12. T t;
  13. explicit adv(T &&t):t(std::forward<T>(t)) {}
  14. template<typename ...U> T &&operator()(U &&...) {
  15. return std::forward<T>(t);
  16. }
  17. };
  18.  
  19. template<typename T> adv<T> make_adv(T &&t) {
  20. return adv<T>{std::forward<T>(t)};
  21. }
  22.  
  23. namespace std {
  24. template<typename T>
  25. struct is_bind_expression< adv<T> > : std::true_type {};
  26. }
  27.  
  28. int main()
  29. {
  30. typedef decltype(&foo) foo_type;
  31. typedef std::result_of<foo_type()>::type foo_rettype;
  32.  
  33. auto chosen_async=
  34. static_cast<std::future<foo_rettype> (*)(foo_type && )>(&std::async<foo_type>);
  35.  
  36. auto async_bound=
  37. std::bind<std::future<foo_rettype>>(chosen_async,
  38. make_adv(std::forward<foo_type>(&foo)));
  39.  
  40. async_bound().wait();
  41. async_bound().wait();
  42. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
Hello, world!
Hello, world!