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.