Re: [Boost-bugs] [Boost C++ Libraries] #7100: unorderd_set<shared_ptr<T> > > - insert does not increment count

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #7100: unorderd_set<shared_ptr<T> > > - insert does not increment count
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-07-09 11:16:15


#7100: unorderd_set<shared_ptr<T> > > - insert does not increment count
------------------------------------------------+---------------------------
  Reporter: Rich Eakin <reakinator@…> | Owner: danieljames
      Type: Bugs | Status: assigned
 Milestone: Boost 1.51.0 | Component: unordered
   Version: Boost 1.50.0 | Severity: Problem
Resolution: | Keywords: unordered_set shared_ptr
------------------------------------------------+---------------------------
Changes (by danieljames):

  * status: new => assigned
  * version: Boost 1.51.0 => Boost 1.50.0
  * milestone: To Be Determined => Boost 1.51.0

Comment:

 I'm afraid that's a feature, not a bug. There's no support for
 `std::shared_ptr` or `std::tr1::shared_ptr`, older versions were
 accidentally picking up the implicit conversion to `bool` and hashing
 based on that - which is really bad as it only returns two possible hash
 values. So 1.51 is going to prevent that happening.

 I might add support for `std::shared_ptr` in a future version, but if you
 really to use it, the best thing to do is to use a custom hash function,
 something like (untested):

 {{{
 struct hash_shared_ptr {
     std::size_t operator()(std::tr1::shared_ptr<int> const& x) {
         boost::hash<int*> hf;
         return hf(x.get());
     }
 };
 }}}

 If you really need `boost::hash` to support `shared_ptr`, then you
 probably should specialize it.

 Btw. you probably know this, but when you use a `shared_ptr` as a set
 element, it stores it based on the address, not the value it points to. I
 just thought I should mention it as people sometimes get confused.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7100#comment:4>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC