I noticed that some copy constructors were being called when using juce::Array::add(lots of values);
The following implementations seem to be missing move/forward semantics with the variadic argument list. I have added them below and can confirm that making the variadic argument list use Rvalue References and std::forward
results in move constructors being used instead of copy constructors being used.
//juce_Array.h
/** Appends multiple new elements at the end of the array. */
template <typename... OtherElements>
void add (ElementType&& firstNewElement, OtherElements&&... otherElements)
{
const ScopedLockType lock (getLock());
values.add (std::move (firstNewElement), std::forward<OtherElements>(otherElements)...);
}
//juce_ArrayBase.h
template <typename... OtherElements>
void add (ElementType&& firstNewElement, OtherElements&&... otherElements)
{
checkSourceIsNotAMember (&firstNewElement);
ensureAllocatedSize (numUsed + 1 + (int) sizeof... (otherElements));
addAssumingCapacityIsReady (std::move (firstNewElement), std::forward<OtherElements>(otherElements)...);
}
template <typename... OtherElements>
void addAssumingCapacityIsReady (ElementType&& firstNewElement, OtherElements&&... otherElements)
{
addAssumingCapacityIsReady (std::move (firstNewElement));
addAssumingCapacityIsReady (std::forward<OtherElements>(otherElements)...);
}
Any comments on why the current implementation of these three functions is passing OtherElements...
by copy instead of moving/forwarding them?