1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Convert ignoreUnused to [[maybe_unused]]

This commit is contained in:
reuk 2022-09-16 19:08:31 +01:00
parent 4351e87bdd
commit 28f2157912
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
141 changed files with 1057 additions and 1209 deletions

View file

@ -727,32 +727,7 @@ public:
@see addSorted, sort
*/
template <typename ElementComparator, typename TargetValueType>
int indexOfSorted (ElementComparator& comparator, TargetValueType elementToLookFor) const
{
ignoreUnused (comparator); // if you pass in an object with a static compareElements() method, this
// avoids getting warning messages about the parameter being unused
const ScopedLockType lock (getLock());
for (int s = 0, e = values.size();;)
{
if (s >= e)
return -1;
if (comparator.compareElements (elementToLookFor, values[s]) == 0)
return s;
auto halfway = (s + e) / 2;
if (halfway == s)
return -1;
if (comparator.compareElements (elementToLookFor, values[halfway]) >= 0)
s = halfway;
else
e = halfway;
}
}
int indexOfSorted (ElementComparator& comparator, TargetValueType elementToLookFor) const;
//==============================================================================
/** Removes an element from the array.
@ -1106,14 +1081,7 @@ public:
@see addSorted, indexOfSorted, sortArray
*/
template <class ElementComparator>
void sort (ElementComparator& comparator,
bool retainOrderOfEquivalentItems = false)
{
const ScopedLockType lock (getLock());
ignoreUnused (comparator); // if you pass in an object with a static compareElements() method, this
// avoids getting warning messages about the parameter being unused
sortArray (comparator, values.begin(), 0, size() - 1, retainOrderOfEquivalentItems);
}
void sort (ElementComparator& comparator, bool retainOrderOfEquivalentItems = false);
//==============================================================================
/** Returns the CriticalSection that locks this array.
@ -1150,4 +1118,43 @@ private:
}
};
//==============================================================================
template <typename ElementType, typename TypeOfCriticalSectionToUse, int minimumAllocatedSize>
template <typename ElementComparator, typename TargetValueType>
int Array<ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize>::indexOfSorted (
[[maybe_unused]] ElementComparator& comparator,
TargetValueType elementToLookFor) const
{
const ScopedLockType lock (getLock());
for (int s = 0, e = values.size();;)
{
if (s >= e)
return -1;
if (comparator.compareElements (elementToLookFor, values[s]) == 0)
return s;
auto halfway = (s + e) / 2;
if (halfway == s)
return -1;
if (comparator.compareElements (elementToLookFor, values[halfway]) >= 0)
s = halfway;
else
e = halfway;
}
}
template <typename ElementType, typename TypeOfCriticalSectionToUse, int minimumAllocatedSize>
template <class ElementComparator>
void Array<ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize>::sort (
[[maybe_unused]] ElementComparator& comparator,
bool retainOrderOfEquivalentItems)
{
const ScopedLockType lock (getLock());
sortArray (comparator, values.begin(), 0, size() - 1, retainOrderOfEquivalentItems);
}
} // namespace juce

View file

@ -542,7 +542,7 @@ private:
template <typename... Elements>
void addImpl (Elements&&... toAdd)
{
ignoreUnused (std::initializer_list<int> { (((void) checkSourceIsNotAMember (toAdd)), 0)... });
(checkSourceIsNotAMember (toAdd), ...);
ensureAllocatedSize (numUsed + (int) sizeof... (toAdd));
addAssumingCapacityIsReady (std::forward<Elements> (toAdd)...);
}
@ -550,7 +550,7 @@ private:
template <typename... Elements>
void addAssumingCapacityIsReady (Elements&&... toAdd)
{
ignoreUnused (std::initializer_list<int> { ((void) (new (elements + numUsed++) ElementType (std::forward<Elements> (toAdd))), 0)... });
(new (elements + numUsed++) ElementType (std::forward<Elements> (toAdd)), ...);
}
//==============================================================================

View file

@ -123,7 +123,7 @@ static void sortArray (ElementComparator& comparator,
@param lastElement the index of the last element in the range (this is non-inclusive)
*/
template <class ElementType, class ElementComparator>
static int findInsertIndexInSortedArray (ElementComparator& comparator,
static int findInsertIndexInSortedArray ([[maybe_unused]] ElementComparator& comparator,
ElementType* const array,
const ElementType newElement,
int firstElement,
@ -131,9 +131,6 @@ static int findInsertIndexInSortedArray (ElementComparator& comparator,
{
jassert (firstElement <= lastElement);
ignoreUnused (comparator); // if you pass in an object with a static compareElements() method, this
// avoids getting warning messages about the parameter being unused
while (firstElement < lastElement)
{
if (comparator.compareElements (newElement, array [firstElement]) == 0)

View file

@ -46,7 +46,6 @@ namespace juce
*/
template <class ObjectClass,
class TypeOfCriticalSectionToUse = DummyCriticalSection>
class OwnedArray
{
public:
@ -531,17 +530,7 @@ public:
@see add, sort, indexOfSorted
*/
template <class ElementComparator>
int addSorted (ElementComparator& comparator, ObjectClass* newObject) noexcept
{
// If you pass in an object with a static compareElements() method, this
// avoids getting warning messages about the parameter being unused
ignoreUnused (comparator);
const ScopedLockType lock (getLock());
auto index = findInsertIndexInSortedArray (comparator, values.begin(), newObject, 0, values.size());
insert (index, newObject);
return index;
}
int addSorted (ElementComparator& comparator, ObjectClass* newObject) noexcept;
/** Finds the index of an object in the array, assuming that the array is sorted.
@ -556,33 +545,7 @@ public:
@see addSorted, sort
*/
template <typename ElementComparator>
int indexOfSorted (ElementComparator& comparator, const ObjectClass* objectToLookFor) const noexcept
{
// If you pass in an object with a static compareElements() method, this
// avoids getting warning messages about the parameter being unused
ignoreUnused (comparator);
const ScopedLockType lock (getLock());
int s = 0, e = values.size();
while (s < e)
{
if (comparator.compareElements (objectToLookFor, values[s]) == 0)
return s;
auto halfway = (s + e) / 2;
if (halfway == s)
break;
if (comparator.compareElements (objectToLookFor, values[halfway]) >= 0)
s = halfway;
else
e = halfway;
}
return -1;
}
int indexOfSorted (ElementComparator& comparator, const ObjectClass* objectToLookFor) const noexcept;
//==============================================================================
/** Removes an object from the array.
@ -818,18 +781,7 @@ public:
@see sortArray, indexOfSorted
*/
template <class ElementComparator>
void sort (ElementComparator& comparator,
bool retainOrderOfEquivalentItems = false) noexcept
{
// If you pass in an object with a static compareElements() method, this
// avoids getting warning messages about the parameter being unused
ignoreUnused (comparator);
const ScopedLockType lock (getLock());
if (size() > 1)
sortArray (comparator, values.begin(), 0, size() - 1, retainOrderOfEquivalentItems);
}
void sort (ElementComparator& comparator, bool retainOrderOfEquivalentItems = false) noexcept;
//==============================================================================
/** Returns the CriticalSection that locks this array.
@ -870,4 +822,57 @@ private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OwnedArray)
};
//==============================================================================
template <class ObjectClass, class TypeOfCriticalSectionToUse>
template <class ElementComparator>
int OwnedArray<ObjectClass, TypeOfCriticalSectionToUse>::addSorted (
[[maybe_unused]] ElementComparator& comparator,
ObjectClass* newObject) noexcept
{
const ScopedLockType lock (getLock());
auto index = findInsertIndexInSortedArray (comparator, values.begin(), newObject, 0, values.size());
insert (index, newObject);
return index;
}
template <class ObjectClass, class TypeOfCriticalSectionToUse>
template <typename ElementComparator>
int OwnedArray<ObjectClass, TypeOfCriticalSectionToUse>::indexOfSorted (
[[maybe_unused]] ElementComparator& comparator,
const ObjectClass* objectToLookFor) const noexcept
{
const ScopedLockType lock (getLock());
int s = 0, e = values.size();
while (s < e)
{
if (comparator.compareElements (objectToLookFor, values[s]) == 0)
return s;
auto halfway = (s + e) / 2;
if (halfway == s)
break;
if (comparator.compareElements (objectToLookFor, values[halfway]) >= 0)
s = halfway;
else
e = halfway;
}
return -1;
}
template <class ObjectClass, class TypeOfCriticalSectionToUse>
template <typename ElementComparator>
void OwnedArray<ObjectClass, TypeOfCriticalSectionToUse>::sort (
[[maybe_unused]] ElementComparator& comparator,
bool retainOrderOfEquivalentItems) noexcept
{
const ScopedLockType lock (getLock());
if (size() > 1)
sortArray (comparator, values.begin(), 0, size() - 1, retainOrderOfEquivalentItems);
}
} // namespace juce

View file

@ -563,31 +563,7 @@ public:
@see addSorted, sort
*/
template <class ElementComparator>
int indexOfSorted (ElementComparator& comparator,
const ObjectClass* objectToLookFor) const noexcept
{
ignoreUnused (comparator);
const ScopedLockType lock (getLock());
int s = 0, e = values.size();
while (s < e)
{
if (comparator.compareElements (objectToLookFor, values[s]) == 0)
return s;
auto halfway = (s + e) / 2;
if (halfway == s)
break;
if (comparator.compareElements (objectToLookFor, values[halfway]) >= 0)
s = halfway;
else
e = halfway;
}
return -1;
}
int indexOfSorted (ElementComparator& comparator, const ObjectClass* objectToLookFor) const noexcept;
//==============================================================================
/** Removes an object from the array.
@ -828,16 +804,7 @@ public:
@see sortArray
*/
template <class ElementComparator>
void sort (ElementComparator& comparator,
bool retainOrderOfEquivalentItems = false) noexcept
{
// If you pass in an object with a static compareElements() method, this
// avoids getting warning messages about the parameter being unused
ignoreUnused (comparator);
const ScopedLockType lock (getLock());
sortArray (comparator, values.begin(), 0, values.size() - 1, retainOrderOfEquivalentItems);
}
void sort (ElementComparator& comparator, bool retainOrderOfEquivalentItems = false) noexcept;
//==============================================================================
/** Reduces the amount of storage being used by the array.
@ -904,4 +871,43 @@ private:
}
};
//==============================================================================
template <class ObjectClass, class TypeOfCriticalSectionToUse>
template <class ElementComparator>
int ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>::indexOfSorted (
[[maybe_unused]] ElementComparator& comparator,
const ObjectClass* objectToLookFor) const noexcept
{
const ScopedLockType lock (getLock());
int s = 0, e = values.size();
while (s < e)
{
if (comparator.compareElements (objectToLookFor, values[s]) == 0)
return s;
auto halfway = (s + e) / 2;
if (halfway == s)
break;
if (comparator.compareElements (objectToLookFor, values[halfway]) >= 0)
s = halfway;
else
e = halfway;
}
return -1;
}
template <class ObjectClass, class TypeOfCriticalSectionToUse>
template <class ElementComparator>
void ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>::sort (
[[maybe_unused]] ElementComparator& comparator,
bool retainOrderOfEquivalentItems) noexcept
{
const ScopedLockType lock (getLock());
sortArray (comparator, values.begin(), 0, values.size() - 1, retainOrderOfEquivalentItems);
}
} // namespace juce