Advertisement
finalpatch

Untitled

Dec 19th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3. #include <string>
  4.  
  5. void foo(std::string s)
  6. {
  7.     std::cout << s << std::endl;
  8. }
  9.  
  10. template<typename... PARAMS, typename... ARGS>
  11. std::function<void()> closure(void (*func)(PARAMS...), ARGS... args)
  12. {
  13.     return std::bind(func, std::forward<PARAMS>(args)...);
  14. }
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18.     char s[10] = "hello";
  19.     auto f = closure(foo, s);
  20.     s[1] = 'a';
  21.     f();
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement