问题描述
#include <compare>
#include <iostream>
int main()
{
auto comp1 = 1.1 <=> 2.2;
auto comp2 = -1 <=> 1;
std::cout << typeid(comp1).name()<<"\n"<<typeid(comp2).name();
}
输出:
struct std::partial_ordering
结构 std::strong_ordering
我知道如果操作数具有整数类型,则运算符返回类型为 std::strong_ordering
的纯右值。我还知道如果操作数具有浮点类型,则运算符会产生 std::partial_ordering
类型的纯右值。
但是为什么我要使用三向比较运算符而不是双向运算符(==
、!=
、<
、<=
、>
,>=
)?这对我有什么好处吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)