jimc
December 15, 2014, 5:07pm
1
Would need some #ifdef around it for old compilers, but would be nice to have:
StringArray::StringArray (const std::initializer_list<const char *> & initialStrings)
{
strings.addArray(initialStrings);
}
and in Array:
template <typename Type>
void addArray(const std::initializer_list<Type> & items)
{
const ScopedLockType lock (getLock());
data.ensureAllocatedSize (numUsed + items.size());
for (auto & i: items)
{
new (data.elements + numUsed) ElementType (i);
++numUsed;
}
}
Probably also with a matching constructor.
jules
December 16, 2014, 9:39am
2
Yeah, I'll add this v. soon. Now that my private projects (i.e. Roli work, Tracktion, etc) are all C++11, it's functionality that I'd find useful myself too.
In case you haven't already done something similar in your private Juce branches, a nice thing can be done with C++11 variadic templates in ListenerList.h to remove the need for the ton of function overloads and use of macros :
template <typename... As, typename... Bs, typename C>
void call (void (C::*callbackFunction) (As...), Bs&&... args)
{
callChecked (static_cast <const DummyBailOutChecker&> (DummyBailOutChecker()),
callbackFunction, std::forward<Bs>(args)...);
}
template <class BailOutCheckerType, typename... As, typename... Bs, typename C>
void callChecked (const BailOutCheckerType& bailOutChecker,
void (C::*callbackFunction) (As...), Bs&&... args)
{
for (Iterator<BailOutCheckerType, ThisType> iter (*this); iter.next (bailOutChecker);)
(iter.getListener()->*callbackFunction) (std::forward<Bs>(args)...);
}
I am using this in my current code and I have tested the Juce demo builds and runs when using this.