I want to implement a small thread wrapper that provides the information if a thread is still active, or if the thread has finished its work. For this I need to pass the functio
The answer by @O'Neil is correct, but I would like to offer a simple lambda approach, since you've tagged this as C++14
.
template
ManagedThread::ManagedThread(Function&& f, Args&&... args):
mActive(false),
mThread([&] /*()*/ { // uncomment if C++11 compatibility needed
mActive = true;
std::forward(f)(std::forward(args)...);
mActive = false;
})
{}
This would eliminate the need for an external function all together.