On 3 November 2010 14:39, Thorsten Ottosen
Den 03-11-2010 19:50, Nevin Liber skrev:
1. What to do if they hold the same type 2. What to do if they hold different types 3. What to do if one side is not a Boost.Any object 4. What to do if operator== isn't defined for the types involved
My armchair answers: 1. Forward to the expression lhs == rhs for the held objects 2. Forward to the expression lhs == rhs for the held objects
2. return false?
That is a possibility. So is throwing or asserting. Giving it slightly more thought, I don't believe you can solve #2 with the answer I proposed, since you need to have the expression "lhs == rhs" somewhere in the source for any two arbitrary types. If a goal is to be able to use the object as a key in an associative container, returning false is probably the best bet. Of course, operator== is not sufficient to use the object as a key in a [unordered_][multi](set|map). You need hashability for the unordered_ case and operator< to implement a strict weak ordering for the other case. The OP did have a SWO but it wasn't very useful (in my opinion). One we could implement is to first order based on typeid(T).before() and a secondary ordering based on std::less or the expression lhs < rhs. -- Nevin ":-)" Liber mailto:nevin@eviloverlord.com (847) 691-1404