Structs with implicitly deleted copy constructors fail to compile. There is a needless copy during pop from queue.
The compiler reports no appropriate default constructor available.
The culprit is here in the thread worker loop code:
if (signal.try_acquire_for(signalWaitInterval)) {
// Guard against empty signals which are terminating indicatorif (!items.empty() && !st.stop_requested()) {
T item;
{ // scope lock to pull item from the deque
std::unique_lock<std::shared_mutex> myWriterLock(items_mutex);
item = items.front();
items.pop_front();
} // end of lock// Delegate to the callback outside the lockcallback(item);
}
}
The fact that we use T item; requires that the object be default constructible whereas our only real requirement is the object type be move constructible.