violating strict weak ordering std::sort

Getting the common segfault with this operator function (the function is really simple. It's just this long because it repeats some conditions.):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
bool operator() (objcopy * lhs, objcopy * rhs)
{
	if (lhs->deleteobj&&rhs->deleteobj) //no
	{
		if (lhs->rndrngpriority!=rhs->rndrngpriority)
		{
		        return lhs->rndrngpriority > rhs->rndrngpriority;
		}
		else if (lhs->posz != rhs->posz)
		{
		        return lhs->posz < rhs->posz;
		}
		else if (lhs->_universal_id != rhs->_universal_id)
			return lhs->_universal_id > rhs->_universal_id;
		else
			return false;
	}
	if (!lhs->deleteobj && rhs->deleteobj)
	{
		return false;
	}
	if (lhs->deleteobj && !rhs->deleteobj)
	{
		return true;
	}
	if (lhs->rndrbackid!=NONE && rhs->rndrbackid!=NONE )
	{
		if (lhs->rndrngpriority!=rhs->rndrngpriority)
		{
		        return lhs->rndrngpriority > rhs->rndrngpriority;
		}
		else if (lhs->posz != rhs->posz)
		{
		        return lhs->posz < rhs->posz;
		}
		else if (lhs->_universal_id != rhs->_universal_id)
		{
			return lhs->_universal_id > rhs->_universal_id;
		}
		else
		{
			return false;
		}
	}
	if (lhs->rndrbackid != NONE && rhs->rndrbackid == NONE )
	{
		return false;
	}
	if (lhs->rndrbackid == NONE && rhs->rndrbackid != NONE )
	{
		return true;
	}
	if (lhs->isbar != rhs->isbar)
	{
		if (lhs->isbar)
			return true;
		if (rhs->isbar)
			return false;
	}        
	else
	{
		if (lhs->rndrngpriority!=rhs->rndrngpriority)
		{
		        return lhs->rndrngpriority > rhs->rndrngpriority;
		}
		else if (lhs->posz != rhs->posz)
		{
		        return lhs->posz < rhs->posz;
		}
		else if (lhs->_universal_id != rhs->_universal_id)
		{
		        return lhs->_universal_id > rhs->_universal_id;
		}
		else
		{
		        return false;
		}
	}
}


Each of these objects has a unique "_universal_id" value, and even in case (even though I don't see how that would happen) the object was compared to itself, the function returns false as it should.

"NONE" is a magic number which is just interpreted as no value.

Thanks in advance!
Last edited on
Each of these objects have a unique "_universal_id" value,


In some cases, the return value has nothing to do with this _universal_id value, so how is that relevant?
I am aware of that, but the comparison involving that member is what happens in the worst scenarios. When I stated that each object has a unique value of that member, I wanted to disregard the property of "irreflexivity" ( as 2 objects will never be the same unless you're comparing the object to itself, which, even though I can't see why std::sort would compare an object to itself, would return False anyway).

Now I just can't see where I screwed up >.<.
What line execution stops on?
Once the segfault is thrown, I am taken to line 68 (where the zpos members are compared).

I am aware one can't try/catch segfault errors, but is there a way I can catch the problem before the segfault happens?
I'm not understanding,
you consciously created a not strict weak ordering and wonder why the sort fails
or you observed that the sort fails, and blame it to the comparison function.

> the function is really simple
explain it.


By the way, ¿can you post the minimal amount of code needed to reproduce your problem?
Topic archived. No new replies allowed.