Initially this may seem overly abstract or philosophical, but I am genuinely interested to see if someone has a convincing argument in favor of one implementation over the other.
Given operator<
for std::pair<T1, T2>
, which would be the better implementation:
return x.first < y.first ||
x.first == y.first && x.second < y.second;
or:
return x.first < y.first ||
!(y.first < x.first) && x.second < y.second;
My understanding is that the two implementations yield equivalent results. Is the latter preferred because it is defined solely in terms of operator<
? Or is it legitimate to assume that a type that is less-than comparible should also be equality comparable? Does anyone else see another point that would sway you between one or the other?
Naturally any answer should be both generic and extensible. So which one would you use and why? Is there a different implementation that's even better than the above?