Equivalence testing using operator less?

Say I have two literals of type T. I would like to check if they were equivalent, but type β€œT” has only the β€œless” operator. How can I test this in C ++?

+5
source share
1 answer

You can emulate the equality operator with a pair of β€œless” comparisons and negatives:

if (!(t1 < t2) && !(t2 < t1)) { printf ("t1 and t2 are equivalent"); } 
+9
source

Source: https://habr.com/ru/post/1204453/


All Articles