Re: [Boost-bugs] [Boost C++ Libraries] #10678: search by a compatible key and default predicates

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #10678: search by a compatible key and default predicates
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-12-05 10:45:56


#10678: search by a compatible key and default predicates
----------------------------------+-------------------------
  Reporter: maxim.yegorushkin@… | Owner: joaquin
      Type: Bugs | Status: closed
 Milestone: To Be Determined | Component: multi_index
   Version: Boost 1.56.0 | Severity: Problem
Resolution: wontfix | Keywords:
----------------------------------+-------------------------
Changes (by joaquin):

 * status: new => closed
 * resolution: => wontfix

Comment:

 Hi Maxim,

 `std::equal_to<void>`: in order to deal with compatible keys for hashed
 indices, you'd need not only transparent equality comparison but also some
 sort of transparent hash functor such as


 {{{
 struct generic_hash
 {
   template<typename T>
   std::size_t operator()(const T& x)const
   {
      boost::hash<T> h;
      return h(x);
   }
 };
 }}}

 but using this is tricky (and dangerous):


 {{{
 multi_index_container<
   std::string,
   indexed_by<
     hashed_unique<identity<std::string>,generic_hash,std::less<void>>
>
> c{"hello"};

 std::cout<<*(c.find("hello"))<<"\n"; // crash
 }}}

 The reason for the problem is: hashing a `std::string` does not yield the
 same value has hashing a `const char*`, so `c.find("hello")` does not find
 the string "hello". This is why [http://open-
 std.org/JTC1/SC22/WG21/docs/papers/2013/n3657.htm N3657] applies only to
 associative containers and has not been extended to unordered associative
 containers.

 As for `std::less<void>`, I'm sympathetic to your proposal but would
 prefer to go in line with the standard, which decided for
 `std::less<void>` to be explicitly provided by the user rather than the
 default.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10678#comment:1>
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:17 UTC