Why does the spaceship operator have only one equal sign in it?

我的未来我决定 提交于 2019-12-10 12:45:08

问题


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.



来源:https://stackoverflow.com/questions/5508338/why-does-the-spaceship-operator-have-only-one-equal-sign-in-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!