Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- #include <string>
- void foo(std::string s)
- {
- std::cout << s << std::endl;
- }
- template<typename... PARAMS, typename... ARGS>
- std::function<void()> closure(void (*func)(PARAMS...), ARGS... args)
- {
- return std::bind(func, std::forward<PARAMS>(args)...);
- }
- int main(int argc, char *argv[])
- {
- char s[10] = "hello";
- auto f = closure(foo, s);
- s[1] = 'a';
- f();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement