mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
Improved efficiency of CSequence::removeIf, but CCollection::removeIf must still use the old algorithm.
This commit is contained in:
@@ -387,6 +387,28 @@ namespace BlackMisc
|
||||
return count;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Remove elements for which a given predicate returns true.
|
||||
* \pre The sequence must be initialized.
|
||||
* \return The number of elements removed.
|
||||
*/
|
||||
template <class Predicate>
|
||||
int removeIf(Predicate p)
|
||||
{
|
||||
auto newEnd = std::remove_if(begin(), end(), p);
|
||||
int count = std::distance(newEnd, end());
|
||||
erase(newEnd, end());
|
||||
return count;
|
||||
}
|
||||
|
||||
//! \copydoc BlackMisc::CContainerBase::removeIf
|
||||
template <class K0, class V0, class... KeysValues>
|
||||
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
|
||||
{
|
||||
// using-declaration doesn't play nicely with injected template names
|
||||
return CSequence::CContainerBase::removeIf(k0, v0, keysValues...);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Remove all elements if they are in other
|
||||
* \pre The sequence must be initialized.
|
||||
@@ -394,13 +416,9 @@ namespace BlackMisc
|
||||
*/
|
||||
int removeIfIn(const CSequence &other)
|
||||
{
|
||||
auto newEnd = std::remove_if(begin(), end(), [&other](const T &v) { return other.contains(v); });
|
||||
int count = std::distance(newEnd, end());
|
||||
erase(newEnd, end());
|
||||
return count;
|
||||
return removeIf([&other](const T &v) { return other.contains(v); });
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Replace elements matching the given element with a replacement.
|
||||
* \return The number of elements replaced.
|
||||
|
||||
Reference in New Issue
Block a user