I need to have a std::vector of safequeues of std::pair for a map-reduce problem, but the compiler gives me always the same error because of an ill-formed definition. I've already read a lot of posts but can't still figure out why the code doesn't work. I'm using a safequeue because of multithreading. This is my safe_queue definition:
template <typename T>
class safe_queue
{
private:
std::mutex d_mutex;
std::condition_variable d_condition;
std::deque<T> d_queue;
public:
safe_queue() {}
void push(T value) {
{
std::unique_lock<std::mutex> lock(this->d_mutex);
d_queue.push_front(value);
}
this->d_condition.notify_one();
}
T pop() {
std::unique_lock<std::mutex> lock(this->d_mutex);
this->d_condition.wait(lock, [=]{ return !this->d_queue.empty(); });
T rc = this->d_queue.back();
this->d_queue.pop_back();
return rc;
}
};
This is the main:
int main(int argc, char * argv[]) {
std::vector<safe_queue<std::pair<std::string, int>>> task_queues;
task_queues.push_back(safe_queue<std::pair<std::string, int>>());
task_queues[0].push(std::pair<std::string, int>("hello", 0));
}
and I'm getting a lot of errors like this:
note: ‘safe_queue<std::pair<std::__cxx11::basic_string<char>, int> >::safe_queue(safe_queue<std::pair<std::__cxx11::basic_string<char>, int> >&&)’ is implicitly deleted because the default definition would be ill-formed:
class safe_queue
required from here
/usr/include/c++/5/ext/new_allocator.h:120:4: error: use of deleted function ‘safe_queue<std::pair<std::__cxx11::basic_string<char>, int> >::safe_queue(safe_queue<std::pair<std::__cxx11::basic_string<char>, int> >&&)’
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }