I've recently implemented a design which uses a sorted container
(std::set) and a custom comparison function. The comparison function is
actually an object with a pointer to another object auxObj. The value
returned by operator() depends in part upon the state of auxObj. No
doubt this is risky in general, though I am careful to ensure that when
the state of auxObj changes, the comparison values between all elements
within the set are unchanged. (To make this more concrete, it's a
scanline algorithm to compute line segment intersections and auxObj
include the location of the scanline.)
Everything works on the platforms I've tested (a couple Unix varieties)
but I'm wondering whether this sort of use is justified by the C++
standard (as opposed to declared "undefined behavior", e.g.). That is,
as long as no elements currently within the set have their respective
comparison values changed, is it OK to change the behavior of the
comparison function?
Thanks,
Mark
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]