c++ - passing template args to std::thread -
im having little problem passing args std::thread calls template function.
template <typename f, typename... a> void start(int interval, f func, a&&... args) { if (_running.load(std::memory_order_acquire)) { stop(); }; _running.store(true, std::memory_order_release); _thread = std::thread([this, interval, func, args]() { while (_running.load(std::memory_order_acquire)) { func(std::forward<a>(args)...); (int = 0; (i <= (interval / 200)) && _running.load(std::memory_order_acquire); i++) std::this_thread::sleep_for(std::chrono::milliseconds(200)); } }); }
edit: added little more detail should able pass function "start" ammount or args
void threadproc(hwnd hwnd) { beep(1000, 100); } start(2000, threadproc, hwnd);
error:
error c3520: 'args': parameter pack must expanded in context note: see reference function template instantiation 'void callback::start<void(__cdecl *)(hwnd),hwnd&>(int,f,hwnd &)' being compiled 1> 1> [ 1> f=void (__cdecl *)(hwnd) 1> ]
_thread = std::thread([this, interval, func, &args...]()
Comments
Post a Comment