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.
1 comment
[ 0.30 ms ] story [ 12.0 ms ] thread