I have an OwnedArray of objects that expose a getName() method. I want to keep it sorted, so I’ve created the obligatory Comparator object which implements compareElements. The question is, how do I determine if an object with a particular name (using the Comparator) already exists, without actually creating one of the objects?
I think this could be easily added to OwnedArray, by simply changing the signature of indexOfSorted:
template <class ElementComparator, class ObjectType> int indexOfSorted (ElementComparator& comparator, ObjectType objectToLookFor) const noexcept
Now it is possible to declare Comparator::compareElements with different types:
int compareElements (String const stringToLookFor, Object const* const objectToCompare);
This idiom could be used everywhere a Comparator is used.