This question already has an answer here:
What is wrong with my template and how to fix it? This is supposed to remove all items from Qt-ish containers, given the predicate function. The compiler yields error 'std::function': 'T::value_type' is not a valid template type argument for parameter '_Fty'
template <typename T>
void eraseIf( T &container, std::function<bool(T::value_type)> predicate)
{
auto it = container.begin();
while( it != container.end() )
{
if( predicate( *it ) )
{
it = container.erase( it );
}
else
{
++it;
}
}
}
Aucun commentaire:
Enregistrer un commentaire