|
Boost Users : |
Subject: Re: [Boost-users] [Any] Operator ==
From: Nevin Liber (nevin_at_[hidden])
Date: 2010-11-03 17:01:41
On 3 November 2010 14:39, Thorsten Ottosen <nesotto_at_[hidden]> wrote:
> 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_at_[hidden]> (847) 691-1404
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net