Question

To avoid a msvc2010 compiler bug, I'm using a user-defined key extrator in a composite_key like that :

enum NodeType
{
     TypeOne = 0,
     TypeTwo
};

struct TypeExtractor
{
 typedef NodeType result_type;

 const result_type& operator()(const boost::shared_ptr<Node>& p) const
 {
  return p->getNodeType();
 }        
};

struct byValueAndType{};

typedef boost::multi_index_container<
 boost::shared_ptr<Node>,
 boost::multi_index::indexed_by<
  boost::multi_index::random_access<>,
  boost::multi_index::ordered_non_unique<
   boost::multi_index::tag<byValueAndType>,
   boost::multi_index::composite_key<
    Node,
    boost::multi_index::const_mem_fun<Node, const std::string&, &Node::getValue>,
    TypeExtractor
   >
  >
 >
> NodeList;

typedef NodeList::nth_index<1>::type NodeListByValueAndType;

This seems to compile well (and vc compiler does not crash anymore), but I have some problems when I try to call an equal_range :

std::pair<Node::NodeListByValueAndType::const_iterator, Node::NodeListByValueAndType::const_iterator> range;

range = _listNode.get<byValueAndType>().equal_range(boost::make_tuple("MyVal", Node::TypeOne));

in my older implementation that was ok, as my composite_key was 'made of' two const_mem_fun. Now the last argument of the composite_key is a custom key extractor and I don't know what to replace 'Node::TypeOne' with. (in my equal_range call)

the compiler says that he's expecting a type of const boost::shared_ptr<Node>&, but I don't realy want to create a shared pointer to a random Node of the good type just for the equal_range... (and it doesn't work anyway)

Was it helpful?

Solution

Use the following composite key extractor:

boost::multi_index::composite_key<
    boost::shared_ptr<Node>,
    boost::multi_index::const_mem_fun<Node, const std::string&, &Node::getValue>,
    TypeExtractor
>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top