SortedSet behaviour dangerous


#1

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


#2

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


#3

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…


#4

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.


#5

Yes, that’s a good idea.


#6

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


#7