FR: StringArray constructor with initializer_list<String>


#1

.h

StringArray (const std::initializer_list<String>& strings);

.cpp

StringArray::StringArray (const std::initializer_list<String>& stringList)
{
    strings.addArray (stringList);
}

Usage example:

StringArray daysOfTheWeek =
{
    TRANS ("Sunday"),
    TRANS ("Monday"),
    TRANS ("Tuesday"),
    TRANS ("Wednesday"),
    TRANS ("Thursday"),
    TRANS ("Friday"),
    TRANS ("Saturday")
};

#2

I thought that was already added:

#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
StringArray (const std::initializer_list<const char*>& strings);
#endif

Aah… never mind… I see your addition :blush:

Rail


#3

To some extent it’s there, but only for const char*!


#4

Yes, I noticed the difference but it was too late to delete my post… hence the :blush:

Cheers,

Rail


#5

Bump, before getting drowned out by DSP module things!


#6

I had been planning to add a bunch of variadic constructors and add methods to the arrays for this kind of thing, which should be more versatile than an initializer_list


#7

Presumably this would mean, in terms of StringArray, that you can specify primitive types and various string formats (CharPointer_UTF8, CharPointer_UTF16)?


#8

I think anything that could be cast to a string would work.