2 ms·
Some types might implement == but not <=>. For these types, == needs to be a primary operator. But for types that implement <=>, I'm not sure why == isn't auto
by cornstalks 7y ago
Some types might implement == but not <=>. For these types, == needs to be a primary operator.
But for types that implement <=>, I'm not sure why == isn't automagically generated.
- tsimionescu 7y agoThere is an explanation in the article - basically, this is done for performance reasons. Especially for large types (e.g. collections) in-equality can short-circuit very quickly, whereas comparison may need to see a large part of the collection before being able to return. The most pathological example is two large arrays of different size, that are element-by-element equal for the first million elements. Equality can return false after seeing the size difference, but <=> needs to reach the millionth-and-1 element before being bale to return a value. The commission was especially concerned because the two operators would be functionally equivalent - so, it would be difficult to rely on testing to make sure the equality operator is also implemented.