How do I compare two boost::any values for equality? How to I compare two containers of boost::any's for equality?
Why doesn't boost::any define this operator? There has to be a reason. There is.
boost::any can, quite literally, hold *anything*. In order to compare the objects being held, you must first know if they _can_ be compared. Consider: const char * initialMessage = "Snowflakes keep falling on my head"; void f() { boost::any multiA(42L); boost::any multiB(initialMessage); //... It doesn't make sense to compare the two 'any' objects. I suppose boost::any could coerce the pointer into a long, and then apply a comparison operator, but the results of that comparison would be meaningless. In order to compare the objects, you'll have to extract them from the any container using an any_cast. Which, of course, means you'll have to know the exact type of the object being held (or which type of a known set of types). -- Jim