Boost logo

Boost Users :

Subject: Re: [Boost-users] Using hash_range with polymorphism
From: Daniel James (dnljms_at_[hidden])
Date: 2011-12-01 09:05:07


On 1 December 2011 07:48, Kelvin Chung <kelvSYC_at_[hidden]> wrote:
> I'm having a hard time reconciling two distinct notions.  Suppose I have a
> class hierarchy with root class Foo, and subclasses Foo1, Foo2, etc. (all of
> which are leaf classes)  Now, suppose that hash_value() is defined for all
> the subclasses but not Foo itself (say, if Foo was abstract).
>
> Now suppose I have this:
>
> struct FooList {
>        std::vector<boost::shared_ptr<Foo>> foos;
> }
>
> std::size_t hash_value(const FooList& list)

You should probably be including something representing the dynamic
type in the hash value, but that depends on how you implement
'operator==' for FooList. If you don't then defining 'hash_value'
doesn't make much sense.


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