Fixed removeIf for Qt version
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
75116364c6
commit
460e83207f
@ -458,7 +458,39 @@ void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::Indexe
|
||||
|
||||
void ResourceModel::removePack(QString& rem)
|
||||
{
|
||||
m_selected.removeIf([&rem](ModPlatform::IndexedPack i) { return rem == i.name; });
|
||||
auto pred = [&rem](ModPlatform::IndexedPack i) { return rem == i.name; };
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
|
||||
m_selected.removeIf(pred);
|
||||
#else
|
||||
{ // well partial implementation of remove_if in case the QT Version is not high enough
|
||||
const auto cbegin = m_selected.cbegin();
|
||||
const auto cend = m_selected.cend();
|
||||
const auto t_it = std::find_if(cbegin, cend, pred);
|
||||
auto result = std::distance(cbegin, t_it);
|
||||
if (result != m_selected.size()) {
|
||||
// now detach:
|
||||
const auto e = m_selected.end();
|
||||
|
||||
auto it = std::next(m_selected.begin(), result);
|
||||
auto dest = it;
|
||||
|
||||
// Loop Invariants:
|
||||
// - it != e
|
||||
// - [next(it), e[ still to be checked
|
||||
// - [c.begin(), dest[ are result
|
||||
while (++it != e) {
|
||||
if (!pred(*it)) {
|
||||
*dest = std::move(*it);
|
||||
++dest;
|
||||
}
|
||||
}
|
||||
|
||||
result = std::distance(dest, e);
|
||||
m_selected.erase(dest, e);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// m_selected.removeAt(qsizetype i)
|
||||
auto pack = std::find_if(m_packs.begin(), m_packs.end(), [&rem](ModPlatform::IndexedPack i) { return rem == i.name; });
|
||||
if (pack == m_packs.end()) { // ignore it if is not in the current search
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user