I am attempting to write a work queue, however I don't really want to know the argument types until later, anyways I am attempting to write something to the effect of
std::queue<std::packaged_task<void()>> workQueue{};
template <typename... Args>
void Foo::doWork(char const* key, Args&&... args)
{
// this already works if called directly but would like to do this work from a separate thread pulling from that queue
}
template <typename... Args>
void Foo::enqueue(char const* key, Args&&... args)
{
// Cannot seem to push this work into a queue type error occurs
workQueue.emplace(std::bind(&Foo::doWork<Args&&...>, this, key, args...));
}
example usage
foo.enqueue("bar", 3, 4, "wham", true);
I am trying to queue up this work as fast as reasonable to keep as much work off the gathering side of this queue. I would simply serialize arguments into something like a stringstream but then I would have to do a sort of cast back to type action on the deserialize side, worry about message + boundaries etc and I would like to avoid that. Anyone got ideas what I could be doing wrong here to get type errors, also attempting to avoid boost so stl containers would be best. I am not able to know the structure ahead of time to just specialize this. Also u want to make sure the arguments are copied into the queue rather then simply referenced so that they are useful even after being de-allocated from the stack off the calling function.