diff --git a/modules/juce_core/containers/juce_Array.h b/modules/juce_core/containers/juce_Array.h index 6eb62dd2b6..3f14cb1dc4 100644 --- a/modules/juce_core/containers/juce_Array.h +++ b/modules/juce_core/containers/juce_Array.h @@ -812,6 +812,28 @@ public: return ElementType(); } + /** Removes an element from the array. + + This will remove the element pointed to by the given iterator, + and move back all the subsequent elements to close the gap. + If the iterator passed in does not point to an element within the + array, behaviour is undefined. + + @param elementToRemove a pointer to the element to remove + @see removeFirstMatchingValue, removeAllInstancesOf, removeRange + */ + void remove (const ElementType* elementToRemove) + { + jassert (elementToRemove != nullptr); + const ScopedLockType lock (getLock()); + + jassert (data.elements != nullptr); + const int indexToRemove = int (elementToRemove - data.elements); + jassert (isPositiveAndBelow (indexToRemove, numUsed)); + + removeInternal (indexToRemove); + } + /** Removes an item from the array. This will remove the first occurrence of the given element from the array.