Initialise NamedValueSets using std::initializer_list


#1

Hi everybody,

I noticed that the NamedValueSet doesn’t have a constructor that takes a std::initializer_list as parameter. This could be useful for writing almost JSON like data with a least possible amount of boilerplate like this:

NamedValueSet data =
{
  {"item1", 20},
  {"item2", "Blabla"}
};

The changes in the JUCE code are trivial. In NamedValueSet.h, add somewhere after the NamedValue definition:

#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
	NamedValueSet(const std::initializer_list<NamedValue>& items) noexcept;
#endif

and in NamedValueSet.cpp:

#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
NamedValueSet::NamedValueSet(const std::initializer_list<NamedValue>& items) noexcept
	: values(items)
{}
#endif

There is already something like this for ValueTrees, but the NamedValueSet deserves some C++11-love too…


#2

Thanks - good request, I’ll add that.

(No need for the macro any more - all the compilers we support can do initialiser lists now)