Daniel Burrows <dburrows <at> algebraicthunk.net> writes:
I'm having trouble getting multi_index's key extractors to play nicely with shared_ptr objects. I'm trying to eliminate my custom hash and equality objects in this code:
class screenshot_cache_entry : /* ... */ { /* ... */
public: const screenshot_key &get_key() const;
/* ... */ };
[...]
typedef multi_index_container< boost::shared_ptr<screenshot_cache_entry>, indexed_by< hashed_unique<tag<by_screenshot_tag>, identity<boost::shared_ptr<screenshot_cache_entry> >, hash_cache_entry, cache_entry_equal>, sequenced<tag<ordered_tag> > >
cache_map;
[...]
typedef multi_index_container< boost::shared_ptr<screenshot_cache_entry>, indexed_by< hashed_unique<tag<by_screenshot_tag>, const_mem_fun< screenshot_cache_entry, const screenshot_key &, &screenshot_cache_entry::get_key> >, sequenced<tag<ordered_tag> > >
cache_map;
[...]
screenshot_cache.cc:526: instantiated from here /usr/include/boost/multi_index/hashed_index.hpp:439: error: no match for call to ‘(const boost::hash<const aptitude::screenshot_key>) (const boost::shared_ptr<gui::<unnamed>::screenshot_cache_entry>&)’
Probably, you have code similar to the following: cache_map m; ... m.find(shared_ptr<gui::<unnamed>::screenshot_cache_entry>(...)); Am I right? Now that you've passed from a hashed index where the key was boost::shared_ptr<screenshot_cache_entry> to one where the key is screenshot_cache_entry, lookup ops have to be passed values convertible to screenshot_cache_entry, not to boost::shared_ptr<screenshot_cache_entry> as was your original situation. Please report back whether this solves your problem. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo