且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

std :: find对象指针的向量

更新时间:2023-11-12 16:34:52

If you want to find a value pointer at by the pointer, instead of a given pointer, you can use std::find_if with a suitable functor:

struct Foo
{
  int i;
};

bool operator==(const Foo& lhs, const Foo& rhs) { return lhs.i == rhs.i; }

std::vector<Foo*> v = ....;

Foo f{42};

std::find_if(v.begin(), v.end(), [&f](const Foo* p) { return *p == f; });