Browse Source

Added flag JUCE_COMPILER_SUPPORTS_INITIALIZER_LIST, and implemented some constructors for StringArray and Array that use C+++11 initialiser lists.

tags/2021-05-28
jules 10 years ago
parent
commit
8c66a5e767
4 changed files with 46 additions and 4 deletions
  1. +25
    -4
      modules/juce_core/containers/juce_Array.h
  2. +10
    -0
      modules/juce_core/system/juce_CompilerSupport.h
  3. +7
    -0
      modules/juce_core/text/juce_StringArray.cpp
  4. +4
    -0
      modules/juce_core/text/juce_StringArray.h

+ 25
- 4
modules/juce_core/containers/juce_Array.h View File

@@ -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


+ 10
- 0
modules/juce_core/system/juce_CompilerSupport.h View File

@@ -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


+ 7
- 0
modules/juce_core/text/juce_StringArray.cpp View File

@@ -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()
{
}


+ 4
- 0
modules/juce_core/text/juce_StringArray.h View File

@@ -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…
Cancel
Save