Why does the spaceship operator have only one equa

2019-06-16 04:37发布

问题:

Why was the spaceship operator <=> chosen to have one equal sign rather than two? Is this seen as inconsistent with one equal sign usually meaning assignment, and two meaning comparison?

回答1:

Why would it have two? There's only one in <=, >= and !=. It's not inconsistent at all. Only == is inconsistent, and that's to avoid conflicts with the assignment operator.



回答2:

The spaceship operator is a combination of a < b, a == b, and a > b. Presumably, the single equals sign was chosen for the same reason it was chosen for >= and <= -- it's simply shorter and easier to read.