I'm coding in C++. I have a project with so many files. I have a vector of pairs named list as follows:
std::vector< std::pair< structure1, double> > list;
and I want to check if for a specific double value z
, there exists an element: el
in the list such that: el.second == z
I want to use find_if
To do so , I've implemented a method : Scheduled
that takes two arguments: the first one is an element like those stored in the list , the second one is the specific value to look for.
I tried several ways but I end up getting an error always
1st way:
bool classA::Scheduled(std::pair< structure1,double > const el, double const t )
{
return el.second==t;
}
inside another method but still in the same class: classA
auto Scheduled1 = std::bind(&classA::Scheduled,this,_1,z);
bool call=std::find_if(list.begin(),list.end(),Scheduled1)=!list.end();
This solution gives the following error:
error: ‘Scheduled1’ does not name a type
2nd way: directly using lambda
bool call = std::find_if(list.begin(),list.end(),[this](std::pair<struct1,double> const& el){return el.second==z;})!=list.end();
z is a member variable of classA This second way of coding gives rise to this error:
error: no matching function for call to
‘find_if(std::vector >::iterator, std::vector >::iterator, classA::method1(int)::__lambda0)’