mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-01 03:10:06 +00:00
Added flag JUCE_COMPILER_SUPPORTS_INITIALIZER_LIST, and implemented some constructors for StringArray and Array that use C+++11 initialiser lists.
This commit is contained in:
parent
bebf363fd1
commit
8c66a5e767
4 changed files with 46 additions and 4 deletions
|
|
@ -96,8 +96,7 @@ public:
|
|||
@param values the array to copy from
|
||||
*/
|
||||
template <typename TypeToCreateFrom>
|
||||
explicit Array (const TypeToCreateFrom* values)
|
||||
: numUsed (0)
|
||||
explicit Array (const TypeToCreateFrom* values) : numUsed (0)
|
||||
{
|
||||
while (*values != TypeToCreateFrom())
|
||||
add (*values++);
|
||||
|
|
@ -109,8 +108,7 @@ public:
|
|||
@param numValues the number of values in the array
|
||||
*/
|
||||
template <typename TypeToCreateFrom>
|
||||
Array (const TypeToCreateFrom* values, int numValues)
|
||||
: numUsed (numValues)
|
||||
Array (const TypeToCreateFrom* values, int numValues) : numUsed (numValues)
|
||||
{
|
||||
data.setAllocatedSize (numValues);
|
||||
|
||||
|
|
@ -118,6 +116,14 @@ public:
|
|||
new (data.elements + i) ElementType (values[i]);
|
||||
}
|
||||
|
||||
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
|
||||
template <typename TypeToCreateFrom>
|
||||
Array (const std::initializer_list<TypeToCreateFrom>& items) : numUsed (0)
|
||||
{
|
||||
addArray (items);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Destructor. */
|
||||
~Array()
|
||||
{
|
||||
|
|
@ -604,6 +610,21 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
|
||||
template <typename TypeToCreateFrom>
|
||||
void addArray (const std::initializer_list<TypeToCreateFrom>& items)
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
data.ensureAllocatedSize (numUsed + (int) items.size());
|
||||
|
||||
for (auto& item : items)
|
||||
{
|
||||
new (data.elements + numUsed) ElementType (item);
|
||||
++numUsed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Adds elements from a null-terminated array of pointers to the end of this array.
|
||||
|
||||
@param elementsToAdd an array of pointers to some kind of object from which elements
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#define JUCE_COMPILER_SUPPORTS_NOEXCEPT 1
|
||||
#define JUCE_COMPILER_SUPPORTS_NULLPTR 1
|
||||
#define JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS 1
|
||||
#define JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS 1
|
||||
|
||||
#if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && ! defined (JUCE_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL)
|
||||
#define JUCE_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL 1
|
||||
|
|
@ -87,6 +88,11 @@
|
|||
#ifndef JUCE_COMPILER_SUPPORTS_ARC
|
||||
#define JUCE_COMPILER_SUPPORTS_ARC 1
|
||||
#endif
|
||||
|
||||
#if __has_feature (cxx_generalized_initializers)
|
||||
#define JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -102,6 +108,10 @@
|
|||
#define JUCE_COMPILER_SUPPORTS_LAMBDAS 1
|
||||
#endif
|
||||
|
||||
#if _MSC_VER >= 1800
|
||||
#define JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS 1
|
||||
#endif
|
||||
|
||||
#if _MSC_VER >= 1900
|
||||
#define JUCE_COMPILER_SUPPORTS_NOEXCEPT 1
|
||||
#define JUCE_DELETED_FUNCTION = delete
|
||||
|
|
|
|||
|
|
@ -86,6 +86,13 @@ StringArray& StringArray::operator= (StringArray&& other) noexcept
|
|||
}
|
||||
#endif
|
||||
|
||||
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
|
||||
StringArray::StringArray (const std::initializer_list<const char*>& stringList)
|
||||
{
|
||||
strings.addArray (stringList);
|
||||
}
|
||||
#endif
|
||||
|
||||
StringArray::~StringArray()
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,10 @@ public:
|
|||
*/
|
||||
StringArray (const wchar_t* const* strings, int numberOfStrings);
|
||||
|
||||
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
|
||||
StringArray (const std::initializer_list<const char*>& strings);
|
||||
#endif
|
||||
|
||||
/** Destructor. */
|
||||
~StringArray();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue