无法编译向量<queue <pair <t1,t2 =“”>&gt;&gt;

时间:2018-05-12 19:39:48

标签: c++ vector mapreduce queue std-pair

对于map-reduce问题,我需要有一个std :: vector的std :: pair安全队列,但由于格式错误,编译器总是给出同样的错误。我已经阅读了很多帖子,但仍然无法弄清楚为什么代码不起作用。因为多线程,我正在使用安全队列。这是我的safe_queue定义:

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;
  }
};

这是主要的:

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));
}

我遇到了很多这样的错误:

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)...); }

0 个答案:

没有答案