3 ms·
How do the literal 0 comparisons fit into the language? Are they special purpose syntax or is it possible to write your own operator that only typechecks if the
by twoodfin 7y ago
How do the literal 0 comparisons fit into the language? Are they special purpose syntax or is it possible to write your own operator that only typechecks if the RHS is a literal 0?
- wyldfire 7y agoAre you confusing the implementation of these operator overloads with their signature? The spaceship returns {neg, 0, pos} and that's why the implementations are like that.
- twoodfin 7y agoI’m referring to this bit of the article: The values of these comparison categories can be compared against the literal 0 (not any int, not an int whose value is 0... just the literal) using any of the six comparison operators...
- wyldfire 7y agoOh, this is particularly confusing, I agree. IIUC it's referring to how you can safely evaluate the return value from a spaceship: by comparing against literal zero. (not how you would overload a comparison with literal zero).
- yokohummer7 7y agoC and C++ already have such a thing, IIUC. The literal 0 is considered the same as nullptr, if compared to another pointer. It is a bit worrying that such an overloaded meaning is added again to the language.