我的谓词函数有什么问题?

时间:2015-04-28 11:08:06

标签: c++ c++11 functional-programming

我试图使用" remove_if " std :: list 的方法。我想删除"特别"元件。这里有一些代码:

WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();  
lp.dimAmount=0.0f;  
dialog.getWindow().setAttributes(lp);  
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

有人可以解释错误的位置吗?

2 个答案:

答案 0 :(得分:3)

您的operator()应该采用Task参数,因为这是tasks中元素的类型。

另一种写作方式:

tasks.remove_if([id](const Task& t) { return t._id == id });

答案 1 :(得分:3)

你有一个错误的仿函数。构造函数应该使用值进行比较,而()运算符应该使用Task:

struct IsEqual {

   IsEqual(const size_t id) : id(id) {}

   bool operator() (const Task& value) {
       return (value._id == id);
   }

   size_t id;
};
相关问题