1
爲了避免msvc2010編譯器錯誤,我使用一個用戶自定義鍵extrator在composite_key這樣的:的boost :: 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;
這似乎很好編譯在我老的實現,這是好的,因爲我composite_key是「由」兩個const_mem_fun
std::pair<Node::NodeListByValueAndType::const_iterator, Node::NodeListByValueAndType::const_iterator> range;
range = _listNode.get<byValueAndType>().equal_range(boost::make_tuple("MyVal", Node::TypeOne));
:(和VC編譯器不會再崩潰),但我有一些問題,當我嘗試調用equal_range。現在composite_key的最後一個參數是一個自定義的鍵提取器,我不知道用'替換'Node :: TypeOne'。 (在我的equal_range調用)
編譯器說,他期待的類型const boost::shared_ptr<Node>&
,但我不希望創建一個共享指針,以良好的類型隨機節點只爲equal_range ...(和它不反正工作)
謝謝你,僅此而已。 – yann 2010-12-18 19:23:38