0

次のようなユーザー定義の構造があります。

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)

上記の操作を効果的に実現する方法について、誰か教えてもらえますか?

4

3 に答える 3

2

list実際には という名前のメンバー関数がありますremove_if:

cell_list.remove_if([](const Cell& cell){
    return cell.dirty == 1;
});
于 2015-07-20T01:46:09.547 に答える