SortedSet behaviour dangerous

Hi all,

In Juce documentation it states:

But when looking at the code, the insertInternal does a “memmove” to put the element at the right position.

It’s dangerous, because if used with a non POD type, the element are not created with constructor when moved (so any reference or pointer on internal data will break). When used with POD however, the comment about the operators > is useless as all POD type have those operator implicitely defined.

On the other side, a OwnedArray lacks a template-based search method so it can be used as a sorted set too.

Let me know what is best to do in that case…
Thanks

BTW, it’s not possible to use reference as the ElementType either, so the only solution for using this is to create a struct with mutable members and move them in copy constructor.

Not so nice too

Oh, it’s really not supposed to be used with proper classes, only simple primitives or structs of primitives that can be easily copied around. I should put something in the docs to that effect…

So, how about adding a templated by ElementComparator “search” method to OwnedArray ?
So if the array is kept sorted, the search method can be as efficient as the sorted set.

Yes, that’s a good idea.

…actually, there’s already a function like that in Array - indexOfSorted()