What is the <=> (“spaceship”, three-way comparison) operator in C++?

后端 未结 4 1105
鱼传尺愫
鱼传尺愫 2020-11-28 18:30

While I was trying to learn about C++ operators, I stumbled upon a strange comparison operator on cppreference.com,* in a table that looked like

4条回答
  •  萌比男神i
    2020-11-28 19:02

    This answer has become irrelevant since the referenced web page has changed

    The web page you are referencing was broken. It was being edited a lot that day and different parts was not in sync. The status when I was looking at it was:

    At the top of the page it lists the currently existing comparison operators (in C++14). There is no <=>there.

    At the bottom of the page, they should have listed the same operators, but they goofed and added this future suggestion.

    gcc doesn't know about <=>yet (and with -std=c++14, never will), so it thinks you meant a <= > b. This is explains the error message.

    If you try the same thing five years from now you will probably get a better error message, something like <=> not part of C++14.

提交回复
热议问题