mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 12:38:48 +03:00
Add remove_if for maps
This commit is contained in:
parent
c03b4e230e
commit
c971602b2d
2 changed files with 17 additions and 7 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue