Opened 6 years ago

Last modified 6 years ago

#12721 new Bugs

intrusive key_of_value requires value to be returned by reference

Reported by: Mathias Gaunard Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: intrusive
Version: Boost 1.61.0 Severity: Problem
Keywords: Cc:

Description

key_of_value requires the key to be returned by reference, this is an unnecessary limitation and prevents using types which return the key by value through an accessor. If the type is returned by value, one will get a warning about returning a reference to a local variable.

Change History (3)

comment:1 by Ion Gaztañaga, 6 years ago

This should have been fixed in Boost 1.62. See ticket 11994 for details:

https://svn.boost.org/trac/boost/ticket/11994

comment:2 by fdegros@…, 6 years ago

Maybe the documentation needs to be updated.

See http://www.boost.org/doc/libs/1_63_0/doc/html/intrusive/map_multimap.html. It still specifies that the key extractor must have a "member function to obtain a const reference to the key stored inside a value_type".

The example also emphasizes that a reference must be returned. This could be updated, especially since the example function returns an int.

Example:

// key_of_value function object, must:
// - be default constructible (and lightweight)
// - define the key type by defining a nested type called "type"
// - define an operator() taking "const value_type&" and
//     returning "type" or "const type &"
struct first_int_is_key
{
   typedef int type;

   type operator()(const MyClass& v) const {  return v.first;  }
};
Note: See TracTickets for help on using tickets.