Browse Source

Added an initialiser list constructor to OwnedArray

tags/2021-05-28
ed 8 years ago
parent
commit
d77f4fe691
1 changed files with 22 additions and 0 deletions
  1. +22
    -0
      modules/juce_core/containers/juce_OwnedArray.h

+ 22
- 0
modules/juce_core/containers/juce_OwnedArray.h View File

@@ -72,6 +72,13 @@ public:
other.numUsed = 0;
}
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
OwnedArray (const std::initializer_list<ObjectClass*>& items)
{
addArray (items);
}
#endif
/** Move assignment operator */
OwnedArray& operator= (OwnedArray&& other) noexcept
{
@@ -469,6 +476,21 @@ public:
}
}
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
template <typename OtherArrayType>
void addArray (const std::initializer_list<OtherArrayType>& 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


Loading…
Cancel
Save