I have a class which contains members A, B, and C, and I want objects of this class stored in a set, where the ABC triplet is known to be unique, and should be the set key. However, the set ordering does not end up as expected.
My comparison functor is:
class MyClassLess { public: bool operator() (const MyClass& t1, const MyClass& t2) const { if(t1.getA() < t2.getA()) return true; if(t1.getB() < t2.getB()) return true; return t1.getC() < t2.getC(); } }; typedef set<MyClass, MyClassLess> SetMyClass; I expected elements in the set to be sorted first by A, and then by B, and finally by C. However, if I iterate through the set from begin to end, the sort order turns out to be:
- B
- C
- A
In other words, I get a group of members which all have a specific value of B, and within that group I see all values of C, and for each value of C I then get all values of A.
Any idea what's going on here?