# Array::add() needs a return value

**URL:** <https://forum.juce.com/t/array-add-needs-a-return-value/10875>\
**Category:** General JUCE discussion\
**Created:** [July 28, 2013, 8:50am UTC](https://forum.juce.com/t/array-add-needs-a-return-value/10875 "2013-07-28T08:50:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [July 28, 2013, 8:50am UTC](https://forum.juce.com/t/array-add-needs-a-return-value/10875/1 "2013-07-28T08:50:18Z")

</div>

It’s great that Array can take a template parameter for TypeOfCriticalSectionToUse but if multiple threads are calling add() how can you ever know which index you got? add() should look like this:

```auto
int add (ParameterType newElement)
{
    const ScopedLockType lock (getLock());
    data.ensureAllocatedSize (numUsed + 1);
    new (data.elements + numUsed++) ElementType (newElement);
    return numUsed;
}
```

Something similar will be needed for addIfNotAlreadyThere.

This goes for all array type containers.
