2014年3月27日 星期四

Using std::find_if on a vector of object

std::vector<Req*> RWbuffer;

Req* rm_req;

struct Comp_Req
{
explicit Comp_Req(Req* i):n(i) {}
inline bool operator()(const Req* m) const { return m == n;}
private:
Req* n;
};

it = find_if(RWbuffer.begin(), RWbuffer.end(), Comp_Req(rm_req));

if (it != RWbuffer.end())
{
  /*
  Do something before Req* remove from RWbuffer
  */
  RWbuffer.erase(it);
}else
{
  cout << "Request not found! Cannot remove! " << endl;

}

http://stackoverflow.com/questions/6679096/using-find-if-on-a-vector-of-object

沒有留言:

張貼留言