[英]Test for equivalence with only less than operator?
Say I have two literals of type 'T'. 假设我有两个类型'T'的文字。 I'd like to test if they were equivalent, but type 'T' only has the "less than" operator implemented.
我想测试它们是否相同,但类型'T'只有“小于”运算符实现。 How would I be able to test this in C++?
我怎样才能在C ++中测试它?
You can emulate the equality operator with a couple of "less than" comparisons and a negation: 您可以通过几个“小于”的比较和否定来模拟相等运算符:
if (!(t1 < t2) && !(t2 < t1)) {
printf ("t1 and t2 are equivalent");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.