gpt4 book ai didi

c++ - 从双端队列中删除某个位置的对象

转载 作者:行者123 更新时间:2023-11-30 02:03:34 24 4
gpt4 key购买 nike

我有这个代码:

 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;

}

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

最佳答案

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

deque 支持随机访问迭代器,它很像指针(事实上,指针是随机访问迭代器的一种),所以你可以只获取开始迭代器并向其添加一个整数获取偏移量,就像使用指针一样。

关于c++ - 从双端队列中删除某个位置的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11717006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com