Is it possible and how to use std::shared_ptr<std::string>
implicitly as index for boost::multi_index_container
?
This code
struct Item
{
std::shared_ptr<std::string> shared_id;
};
using ItemsIndexed = boost::multi_index_container<
Item,
boost::multi_index::indexed_by<
boost::multi_index::ordered_non_unique<
boost::multi_index::member<Item, std::string, &Item::shared_id>>>>;
gives an error
value of type 'std::shared_ptr<std::string> Item::*' is not implicitly convertible to 'std::string Item::*'
Or the only way is to provide the key extractor that will dereference shared_pointer:
struct Item
{
std::shared_ptr<std::string> shared_id;
std::string shared_id_extractor() const
{
return *shared_id;
}
};
using ItemsIndexed = boost::multi_index_container<
Item,
boost::multi_index::indexed_by<
boost::multi_index::ordered_non_unique<
boost::multi_index::
const_mem_fun<Item, std::string, &Item::shared_id_extractor>>>>;