Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有两个“T”类型的文字。我想测试它们是否相等,但类型“T”只实现了“小于”运算符。我怎么能在 C++ 中测试这个?
您可以使用几个“小于”比较和一个否定来模拟相等运算符:
if (!(t1 < t2) && !(t2 < t1)) { printf ("t1 and t2 are equivalent"); }