1

我有这个代码:

 bool tuple_compare(boost::tuple<ppa::Node*, ppa::Node*, ppa::Node*, bool> &tuple_from_done)
  {
  for(int i = 0; i < deque_wait.size(); i++) {

      boost::tuple<ppa::Node*, ppa::Node*, ppa::Node*, bool> tuple_from_wait = deque_wait.at(i);
      ppa::Node *father = boost::get<0>(tuple_from_wait);
      ppa::Node *son = boost::get<0>(tuple_from_wait);
      ppa::Node *second_son = boost::get<2>(tuple_from_wait);

      bool has_seq = boost::get<3>(tuple_from_wait);

      cout << "checking this two " << boost::get<1>(tuple_from_wait)->get_name() <<  " bool sequence "
              <<  boost::get<1>(tuple_from_wait)->node_has_sequence_object  << " and this " 
              << boost::get<2>(tuple_from_wait)->get_name() << " bool seq " <<  boost::get<2>(tuple_from_wait)->node_has_sequence_object
              << " with " << boost::get<0>(tuple_from_done)->get_name() << endl;

      if(boost::get<0>(tuple_from_done)->get_name() == boost::get<1>(tuple_from_wait)->get_name()
              || boost::get<0>(tuple_from_done)->get_name() == boost::get<2>(tuple_from_wait)->get_name())
      {
         cout << " found in here this we need to check if there is something if the sons have a sequences!!!! " << endl; 

         if(boost::get<1>(tuple_from_wait)->node_has_sequence_object == true && boost::get<2>(tuple_from_wait)->node_has_sequence_object == true) 
         {
             cout << " ding, ding, we have one ready!!!" << endl;

             return true;
         }
         else
         {
             cout << "not ready yet" << endl;
         }

        }    

       }

  return false;

}

现在我需要删除在“叮,叮”行中找到的对象,但我不知道该怎么做,我知道迭代器使用得很好我实际上必须从 deque_wait 中删除这个元组并移动它到deque_run,但我还不太明白,所以你能帮助我吗,谢谢。

4

1 回答 1

4
deque_wait.erase(deque_wait.begin() + i);
//               ^^^^^^^^^^^^^^^^^^^^^^
//               that's an iterator

deque支持随机访问迭代器,它非常像指针(实际上,指针是一种随机访问迭代器),所以你可以只获取开始迭代器并添加一个整数来获取偏移量,就像你可以做的那样一个指针。

于 2012-07-30T07:30:43.347 回答