我想根据属性搜索由指向自定义类型的指针组成的向量。但我不知道如何正确定义 lambda。这是我的代码。
template<typename T>
class State {
public:
unsigned int id;
...
};
另一个持有状态指针向量的类:
class System {
public:
std::vector<State<type>*> list_;
State<type>* getState(unsigned int id) {
auto it = find_if(list_.begin(), list_.end(), [id](const State<type>* st&) {st->id == id;});
if (it == list_.end())
return nullptr;
return *it;
}
...
};
但是我在 lambda 定义中使用了引用和指针。list_
检查是否包含 astate
的正确方法是id
什么?
感谢帮助!
问候