receive a value and compare it to the list to see if it is there.
maybe with std::find_if :
//btw. I'd rather use private inheritance (if any), in order to prevent gnuComponentList* to QList<gnyComponent>* conversions
// (QList destructor is not virtual)
class gnyComponentList:private QList<gnyComponent>
{
protected:
virtual bool containsItem( gnyComponent * item )
{
const auto it = std::find_if(begin(),
end(),
[&](const gnyComponent& cmp){
return cmp.getID().compare(item->getID()) == 0; // i dont know when gnyComponents are equal exactly
});
return it!=end();
}
};
//btw. I'd rather use private inheritance (if any), in order to prevent gnuComponentList* to QList<gnyComponent>* conversions
// (QList destructor is not virtual)
class gnyComponentList:private QList<gnyComponent>
{
protected:
virtual bool containsItem( gnyComponent * item )
{
const auto it = std::find_if(begin(),
end(),
[&](const gnyComponent& cmp){
return cmp.getID().compare(item->getID()) == 0; // i dont know when gnyComponents are equal exactly
});
return it!=end();
}
};
To copy to clipboard, switch view to plain text mode
Alternatively if you can change gnyComponent class, you can implement "operator==" and use QList::contains:
class gnyComponentList:private QList<gnyComponent>
{
protected:
virtual bool containsItem( gnyComponent * item )
{
return contains(*item); // requres gnyComponent to have an implementation of "operator=="
}
};
class gnyComponentList:private QList<gnyComponent>
{
protected:
virtual bool containsItem( gnyComponent * item )
{
return contains(*item); // requres gnyComponent to have an implementation of "operator=="
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks