Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test for equivalence with only less than operator?

Say I have two literals of type 'T'. I'd like to test if they were equivalent, but type 'T' only has the "less than" operator implemented. How would I be able to test this in C++?

like image 265
user3019324 Avatar asked Oct 10 '14 20:10

user3019324


1 Answers

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");
}
like image 161
Mureinik Avatar answered Sep 21 '22 23:09

Mureinik