mirror of https://github.com/axmolengine/axmol.git
issue #2790: Adds Vector<T>::sort method, adds Vector::removeObject(object, toRemoved).
This commit is contained in:
parent
a12a101548
commit
6f13a111ae
|
@ -230,13 +230,14 @@ public:
|
|||
}
|
||||
|
||||
/** Remove a certain object */
|
||||
void removeObject(T object)
|
||||
void removeObject(T object, bool toRelease = true)
|
||||
{
|
||||
CCASSERT(object != nullptr, "The object should not be nullptr");
|
||||
auto iter = std::find(_data.begin(), _data.end(), object);
|
||||
if (iter != _data.end())
|
||||
_data.erase(iter);
|
||||
object->release();
|
||||
if (toRelease)
|
||||
object->release();
|
||||
}
|
||||
|
||||
/** Removes an element with a certain index */
|
||||
|
@ -341,6 +342,16 @@ public:
|
|||
});
|
||||
}
|
||||
|
||||
void sort(const std::function<bool(T, T)>& callback)
|
||||
{
|
||||
if (empty())
|
||||
return;
|
||||
|
||||
std::sort(_data.begin(), _data.end(), [&callback](T a, T b) -> bool{
|
||||
return callback(a, b);
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------
|
||||
// Iterators
|
||||
// ------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue