2010-12-17 2 views
1

msvc2010コンパイラのバグを回避するためには、私はそのようなcomposite_key内のユーザー定義キーextrator使用しています:ブースト:: multi_indexユーザ定義キー抽出し、複合キー

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; 

をこれがうまくコンパイルすると思われます私はequal_rangeを呼び出すしようとすると、(およびVCコンパイラはもうクラッシュしない)が、私はいくつかの問題を持っている:

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

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

を私composite_keyが2 const_mem_fun「製」だったとして、OKだった私の古い実装で。今度はcomposite_keyの最後の引数はカスタムキー抽出子で、 'Node :: TypeOne'を何に置き換えるべきかわかりません。 (私のequal_range呼び出しで)

const boost::shared_ptr<Node>&と期待していますが、実際にequal_rangeだけの良いタイプのランダムなノードへの共有ポインタを作成したくありません。それはとにかく動作しません)

答えて

1

次複合キー抽出器を使用します。

boost::multi_index::composite_key< 
    boost::shared_ptr<Node>, 
    boost::multi_index::const_mem_fun<Node, const std::string&, &Node::getValue>, 
    TypeExtractor 
> 
+0

は、それはそれだった、ありがとうございました。 – yann