putting pointers to objects in a set

Started by
21 comments, last by DevFred 14 years, 8 months ago
Quote:Original post by SiCrane
A pointer converted to an integer of sufficient size (if any such exists on the implementation) and back to the same pointer type will have its original value


Which is all the OP needs; for that to work, distinct pointers must map to distinct integers, and integers have the necessary ordering properties for the set.
Advertisement
I think the behaviour of the original snippet is defined. std::set uses std::less by default instead of op <. And std::less guarantees total ordering even for pointer types:
Quote:ISO/IEC 14882:2003 20.3.3.8
For templates greater, less, greater_equal, and less_equal, the specializations for any pointer type yield a total order, even if the built-in operators <, >, <=, >= do not.
Really? Yay!

This topic is closed to new replies.

Advertisement