Add remove_if for maps

This commit is contained in:
Konstantinos Sideris 2018-04-27 18:19:43 +03:00
parent c03b4e230e
commit c971602b2d
2 changed files with 17 additions and 7 deletions

View file

@ -55,6 +55,19 @@ scaleDown(uint64_t max_width, uint64_t max_height, const ImageType &source)
final_width, final_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
//! Delete items in a container based on a predicate.
template<typename ContainerT, typename PredicateT>
void
erase_if(ContainerT &items, const PredicateT &predicate)
{
for (auto it = items.begin(); it != items.end();) {
if (predicate(*it))
it = items.erase(it);
else
++it;
}
};
//! Calculate the Levenshtein distance between two strings with character skipping.
int
levenshtein_distance(const std::string &s1, const std::string &s2);

View file

@ -183,15 +183,12 @@ RoomList::initialize(const QMap<QString, RoomInfo> &info)
void
RoomList::cleanupInvites(const std::map<QString, bool> &invites)
{
if (invites.empty())
if (invites.size() == 0)
return;
for (auto it = rooms_.begin(); it != rooms_.end();) {
if (it->second->isInvite() && (invites.find(it->first) == invites.end()))
it = rooms_.erase(it);
else
++it;
}
utils::erase_if(rooms_, [invites](auto &room) {
return room.second->isInvite() && (invites.find(room.first) == invites.end());
});
}
void