[C++] STL list - how to find a list element by its object fields
- by Dominic Bou-Samra
I have a list:
list<Unit *> UnitCollection;
containing Unit objects, which has an accessor like:
bool Unit::isUnit(string uCode)
{
if(this->unitCode == uCode)
return true;
else
return false;
}
How do I search my UnitCollection list by uCode and return the corresponding element (preferably it's index).
I have looked at the find() method, but i'm not sure you can pass a boolean method in instead of a searched item parameter if that makes sense.