Let's consider the following example:
#include <iostream>
#include <set>
struct Obj {
int x;
int operator<=> (const Obj& obj) const {
std::cout << __FUNCTION__ << " " << *this << " " << obj << std::endl;
return x - obj.x;
}
friend std::ostream& operator<< (std::ostream& os, const Obj& obj);
};
std::ostream& operator<< (std::ostream& os, const Obj& obj) {
return os << "{ x: " << obj.x << " }";
}
int main() {
std::set<Obj> st2{{1}, {2}};
return 0;
}
It would yield two rows:
operator<=> { x: 1 } { x: 2 }
operator<=> { x: 2 } { x: 1 }
At this moment I wonder why it performs two comparisons.
UPD: g++-10 version: 10.2.0
{2}, {1})..