<=>是c++20中新出的一个运算符,操作方法如下:
左值<=>右值
左值类型:int ,char,string,struct*,<>[].......
右值类型:int ,char,string,struct*,<>[].......
计算方法
if(左值<右值)return -1;(std::strong_ordering::less)
else if(左值==右值)return 0;(std::strong_ordering::equal)
else if(左值>右值)return -1;(std::strong_ordering::greater)
else return 'inf';
其实std::strong_ordering和std::partial_ordering和-1,+1是一样的他们的定义如下:
+--------------------------------------------------------------------+
| | Numeric values | Non-numeric |
| Category +-----------------------------------+ |
| | -1 | 0 | +1 | values |
+------------------+------+------------+---------------+-------------+
| strong_ordering | less | equal | greater | |
| weak_ordering | less | equivalent | greater | |
| partial_ordering | less | equivalent | greater | unordered |
| strong_equality | | equal | nonequal | |
| weak_equality | | equivalent | nonequivalent | |
+------------------+------+------------+---------------+-------------+
这个运算符在cmd .bat .hpml同样适用
$num1=1;
$num2=2;
$num3=1;
echo $num1<=>$num2; //输出-1
echo "<br>";
echo $num1<=>$num3; //输出0
echo "<br>";
echo $num2<=>$num3; //输出1