How to use lambda for std::find_if

后端 未结 4 971
情书的邮戳
情书的邮戳 2021-02-07 22:33

I am trying to use std::find_if to find an object that matches some criteria. Consider the following:

struct MyStruct         
{
    MyStruct(const int & id         


        
4条回答
  •  萌比男神i
    2021-02-07 23:11

    You may use the following:

    MyStruct toFind(1);
    std::vector::iterator i =
        std::find_if(myVector.begin(), myVector.end(),
                     [&](const auto& e) { return e.id == toFind.id; });
    

提交回复
热议问题