43 using ParameterType =
typename TypeHelpers::ParameterType<ElementType>::type;
45 template <
class OtherElementType,
class OtherCriticalSection>
59 : elements (std::move (
other.elements)),
60 numAllocated (
other.numAllocated),
61 numUsed (
other.numUsed)
63 other.numAllocated = 0;
87 : elements (std::move (
other.elements)),
88 numAllocated (
other.numAllocated),
89 numUsed (
other.numUsed)
91 other.numAllocated = 0;
106 elements = std::move (
other.elements);
107 numAllocated =
other.numAllocated;
108 numUsed =
other.numUsed;
110 other.numAllocated = 0;
117 template <
class OtherArrayType>
120 if (size() != (
int)
other.size())
132 template <
class OtherArrayType>
135 return ! operator== (
other);
139 inline ElementType& operator[] (
const int index)
noexcept
143 return elements[index];
146 inline const ElementType& operator[] (
const int index)
const noexcept
150 return elements[index];
153 inline ElementType getValueWithDefault (
const int index)
const noexcept
158 inline ElementType getFirst()
const noexcept
160 return numUsed > 0 ? elements[0] : ElementType();
163 inline ElementType getLast()
const noexcept
165 return numUsed > 0 ? elements[numUsed - 1] : ElementType();
169 inline ElementType* begin() noexcept
174 inline const ElementType* begin()
const noexcept
179 inline ElementType* end() noexcept
181 return elements + numUsed;
184 inline const ElementType* end()
const noexcept
186 return elements + numUsed;
189 inline ElementType* data() noexcept
194 inline const ElementType* data()
const noexcept
199 inline int size()
const noexcept
204 inline int capacity()
const noexcept
230 jassert (numAllocated <= 0 || elements !=
nullptr);
241 for (
int i = 0; i < numUsed; ++i)
242 elements[i].~ElementType();
248 void swapWith (ArrayBase&
other)
noexcept
250 elements.swapWith (
other.elements);
279 template <
typename Type>
287 template <
typename TypeToCreateFrom>
290 ensureAllocatedSize (numUsed + (
int) items.
size());
292 for (
auto& item : items)
293 new (elements + numUsed++) ElementType (item);
296 template <
class OtherArrayType>
303 addAssumingCapacityIsReady (e);
306 template <
class OtherArrayType>
388 #if defined (__GNUC__) && __GNUC__ < 5 && ! defined (__clang__)
389 static constexpr auto isTriviallyCopyable = std::is_scalar_v<ElementType>;
391 static constexpr auto isTriviallyCopyable = std::is_trivially_copyable_v<ElementType>;
395 template <
typename Type>
398 if constexpr (isTriviallyCopyable && std::is_same_v<Type, ElementType>)
405 auto* start = elements + numUsed;
415 if constexpr (isTriviallyCopyable)
423 for (
int i = 0; i < numUsed; ++i)
425 new (
newElements + i) ElementType (std::move (elements[i]));
426 elements[i].~ElementType();
439 return elements + numUsed;
448 if constexpr (isTriviallyCopyable)
456 auto* end = elements + numUsed;
462 new (--
newEnd) ElementType (std::move (*(--end)));
471 if constexpr (isTriviallyCopyable)
484 moveAssignElement (destination++, std::move (*(source++)));
487 (destination++)->~ElementType();
494 if constexpr (isTriviallyCopyable)
496 char tempCopy[
sizeof (ElementType)];
517 ElementType
tempCopy (std::move (*e));
522 for (
int i = 0; i < delta; ++i)
524 moveAssignElement (e, std::move (*(e + 1)));
530 for (
int i = 0; i < -delta; ++i)
532 moveAssignElement (e, std::move (*(e - 1)));
537 moveAssignElement (e, std::move (
tempCopy));
545 (checkSourceIsNotAMember (
toAdd), ...);
546 ensureAllocatedSize (numUsed + (
int)
sizeof... (
toAdd));
547 addAssumingCapacityIsReady (std::forward<Elements> (
toAdd)...);
553 (
new (elements + numUsed++) ElementType (std::forward<Elements> (
toAdd)), ...);
557 void moveAssignElement (ElementType* destination, ElementType&& source)
559 if constexpr (std::is_move_assignable_v<ElementType>)
561 *destination = std::move (source);
565 destination->~ElementType();
566 new (destination) ElementType (std::move (source));
570 void checkSourceIsNotAMember ([[
maybe_unused]]
const ElementType& element)
581 HeapBlock<ElementType> elements;
582 int numAllocated = 0, numUsed = 0;
584 template <
class OtherElementType,
class OtherCriticalSection>
585 friend class ArrayBase;