[Boost-bugs] [Boost C++ Libraries] #11994: Support intrusive container key extractors that return the key by value

Subject: [Boost-bugs] [Boost C++ Libraries] #11994: Support intrusive container key extractors that return the key by value
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-02-17 04:22:40


#11994: Support intrusive container key extractors that return the key by value
------------------------------+------------------------
 Reporter: fdegros@… | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: intrusive
  Version: Boost 1.60.0 | Severity: Problem
 Keywords: |
------------------------------+------------------------
 [http://www.boost.org/doc/libs/1_60_0/doc/html/intrusive/map_multimap.html
 Map and multimap-like interface for associative containers] specifies that
 the "key extractor" passed by `key_of_value` must provide a member
 function to obtain a const reference to the key stored inside a
 `value_type`.

 According to my experience, if the key extractor returns the key by value
 instead of const reference, then the code compiles but the program crashes
 a run time. This is a real pitfall.

 Consider supporting key extraction by value as well. It would allow to use
 keys that are not stored directly in the value_type, or not directly
 accessible by reference.

 For example:
 {{{#!c++

 using boost::intrusive;

 struct my_node: set_base_hook<> {
   string s;
 };

 // The key is the length of my_node::s.
 struct by_length {
   using key_type = std::size_t;

   // Return key by value.
   std::size_t operator()(const my_node& n) const {
     return n.s.length();
   }
 };

 multiset<std::string, key_of_value<by_length>> v;
 v.insert(...);

 // Find a string by length.
 const auto it = v.find(3);
 ...

 }}}

 If this is not possible, then add a static assertion to make sure that the
 code doesn't compile at all.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11994>
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:19 UTC