I have a container object :
R Container;
R is of type list<T*> or vector<T*>
I am trying to write the following function:
template<typename T, typename R>
T& tContainer_t<T, R>::Find( T const item ) const
{
typename R::const_iterator it = std::find_if(Container.begin(), Container.end(), [item](const R&v) { return item == v; });
if (it != Container.end())
return (**it);
else
throw Exception("Item not found in container");
}
When trying the method (v is an object of my class)
double f = 1.1;
v.Find(f);
I get binary '==' : no operator found which takes a left-hand operand of type 'const double' (or there is no acceptable conversion)
I am confused with the lambda expression syntax and what i should write there and couldn’t find any friendly explanation.
What is wrong ? 10x.
Missing a bit of context, but I note:
**itso you possibly want to compare*v==itemtconst R&vwhere I suspect you meantconst T&vinto the lambdaHere is working code, stripped of the missing class references: