34template <
typename ElementComparator>
35struct SortFunctionConverter
37 SortFunctionConverter (ElementComparator& e) : comparator (e) {}
38 SortFunctionConverter (
const SortFunctionConverter&) =
default;
40 template <
typename Type>
41 bool operator() (Type a, Type b) {
return comparator.compareElements (a, b) < 0; }
44 ElementComparator& comparator;
46 SortFunctionConverter& operator= (
const SortFunctionConverter&) =
delete;
80template <
class ElementType,
class ElementComparator>
81static void sortArray (ElementComparator& comparator,
82 ElementType*
const array,
85 const bool retainOrderOfEquivalentItems)
87 jassert (firstElement >= 0);
89 if (lastElement > firstElement)
93 if (retainOrderOfEquivalentItems)
94 std::stable_sort (array + firstElement, array + lastElement + 1, converter);
96 std::sort (array + firstElement, array + lastElement + 1, converter);
125template <
class ElementType,
class ElementComparator>
126static int findInsertIndexInSortedArray ([[maybe_unused]] ElementComparator& comparator,
127 ElementType*
const array,
128 const ElementType newElement,
132 jassert (firstElement <= lastElement);
134 while (firstElement < lastElement)
136 if (comparator.compareElements (newElement, array [firstElement]) == 0)
143 const int halfway = (firstElement + lastElement) >> 1;
145 if (halfway == firstElement)
147 if (comparator.compareElements (newElement, array [halfway]) >= 0)
152 else if (comparator.compareElements (newElement, array [halfway]) >= 0)
154 firstElement = halfway;
158 lastElement = halfway;
183template <
class ElementType>
187 using ParameterType =
typename TypeHelpers::ParameterType<ElementType>::type;
190 static int compareElements (ParameterType first, ParameterType second)
192 return (first < second) ? -1 : ((second < first) ? 1 : 0);