From d77f4fe691551ca478b2ce3d033b961f36eac425 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 20 Feb 2018 17:22:28 +0000 Subject: [PATCH] Added an initialiser list constructor to OwnedArray --- .../juce_core/containers/juce_OwnedArray.h | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/juce_core/containers/juce_OwnedArray.h b/modules/juce_core/containers/juce_OwnedArray.h index c581be7beb..83f0aa01c3 100644 --- a/modules/juce_core/containers/juce_OwnedArray.h +++ b/modules/juce_core/containers/juce_OwnedArray.h @@ -72,6 +72,13 @@ public: other.numUsed = 0; } + #if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS + OwnedArray (const std::initializer_list& items) + { + addArray (items); + } + #endif + /** Move assignment operator */ OwnedArray& operator= (OwnedArray&& other) noexcept { @@ -469,6 +476,21 @@ public: } } + #if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS + template + void addArray (const std::initializer_list& items) + { + const ScopedLockType lock (getLock()); + data.ensureAllocatedSize (numUsed + (int) items.size()); + + for (auto* item : items) + { + data.elements[numUsed] = item; + ++numUsed; + } + } + #endif + /** Adds copies of the elements in another array to the end of this array. The other array must be either an OwnedArray of a compatible type of object, or an Array