Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- #include "Util.hpp"
- // I am well aware that his leaks memory!
- // what I had in windows, which compiled in VS
- // however, sometimes the stack fucked up, and arguments supplied were seemingly random
- // I couldn't track this down, until I tried to compile this in G++ 4.8
- template<typename Args...>
- void CallIn(double seconds, std::function<void(Args...)> callback, Args... params)
- {
- std::thread* pThread = new std::thread([&]()
- {
- Util::Sleep(seconds);
- callback(params...);
- });
- }
- //Fixed function:
- template<typename Args...>
- void CallIn(double seconds, std::function<void(Args...)> callback, Args... params)
- {
- auto func = [](double sec, std::function<void(Args...)> cb, Args... args)
- {
- Util::Sleep(sec);
- cb(args...)
- };
- auto bound = std::bind(func, sec, cb, args...);
- std::thread *pThread = new std::thread(bound);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement