Test for equivalence with only less than operator?
Asked Answered
J

1

6

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++?

Jampan answered 10/10, 2014 at 20:31 Comment(0)
J
10

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");
}
Jennettejenni answered 10/10, 2014 at 20:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.