
The Evil Within the Comparison Functions (C,C++,C#) - DmitryNovikov
https://software.intel.com/en-us/articles/the-evil-within-the-comparison-functions
======
jepler
This is why you should use clever language features such as macros (C) and
pointers to member data (C++). If your code looks like this, there's no scope
for accidentally comparing two fields in the same object, or comparing
different fields in the two different objects:

    
    
            return less_helper(pt1, pt2)(&pt::x)(&pt::y);
    

with pt::x and pt::y being integers, this ends up the same size as the open-
coded version on the clang versions I tested, but two instructions longer on
the gcc versions I tested, because gcc does not succeed in eliminating a
needless comparison of y<x. (x86_64 in both cases) This could be fixed by
taking away the automatic conversion to bool and requiring the last comparison
in the chain to specify that it _IS_ the last one.

