I’m porting a large library from C++ to Xojo.
Several of the objects have custom sorting.
I tried implementing the operator_compare in Xojo, but I get different results than the C++ code.
I’m suspecting that it’s to do with comparing functionally equivalent objects.
While the values compared sort the same, the objects that they reference are in a different order.
The C++ code is as follows.
[code]// sort into descending order
inline bool operator<(const ANT &a, const ANT &b)
{
if( a.a == b.a ){
return a.b < b.b;
}
return a.a < b.a;
};[/code]
After trying to have the operator_compare do it’s thing, I altered my code to try to match the above, and I used a bubble sort.
Discouraged: the xojo code below + bubble sort have the same results, both of which are different than the original C++
The code is implemented in a method named isLessThan on the object. It looks like thi.
If a = s.a Then
Return b < s.b
End If
Return a < s.a
This doesn’t seem like it should be rocket science, and yet I’m either too foggy from lack of sleep, or I’m just missing something obvious.
Thoughts or suggestions?
Further info.
the object’s AB that I put in are:
*the first column is an non-unique and non-compared id.
You can see that the column 2 and 3 are the same in C++ and Xojo, but the first column is different, indicating that the actual objects referenced sequence differently.
7: 0 1
7: 2 0
6: 0 1
6: 1 0
5: 3 1
5: 2 0
4: 3 1
4: 1 0
in C++ I get back
7: 0 1
6: 0 1
4: 1 0
6: 1 0
7: 2 0
5: 2 0
4: 3 1
5: 3 1
in Xojo I get back
7: 0 1
6: 0 1
6: 1 0
4: 1 0
7: 2 0
5: 2 0
5: 3 1
4: 3 1
Thanks in advance!