From c334530f2980c14b6484589b296e2cbe4837539a Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 10 Dec 2015 10:35:30 +0000 Subject: [PATCH] Added new method Array::remove that takes an element pointer. --- modules/juce_core/containers/juce_Array.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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.