我有一个用户定义的结构是这样的:删除std:list <User_Define>中满足特定条件的元素的最佳方法是什么?
struct Cell{
int dirty;
double data;
Cell* c;
// bool operator==(const struct Cell& other) {
// /* I am not sure if I need this function here...*/
// }
};
然后,我定义如下列表:
list<Cell> cell_list;
我想要做的就是在“cell_list”删除任何元素满足
(certain_cell.dirty == 1)
可能有人给我如何有效地实现上述操作的某些指令的条件?
使用'remove_if'。像'cell_list.remove_if([](Cell&c){return c.dirty;});'和'dirty'应该可能是'bool'。 – ooga
@ooga答案属于答案。 – Barry
@Barry这是一个微不足道的问题,我想我会给OP一个删除它的机会。 – ooga