
Tal Agmon ha escrito:
Please see below code
OK, now I can reproduce it. This is indeed MSVC 6.0 bug (one more): I've tried with GCC and ICC 7.1, and everything goes smooth. Fortunately, you can always resort to manually writing your key extractors, as described in http://tinyurl.com/l3g6u; the following workaround with user-defined key extractors has been checked to work with MSVC 6.5. Hope it helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo ******** BEGIN CODE ******** #include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/mem_fun.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> typedef int handle; typedef int group_id; struct NodeBase:boost::enable_shared_from_this<NodeBase> { virtual ~NodeBase(){} virtual group_id memberOf()const=0; virtual handle getHandle()const=0; }; struct NodeType:NodeBase { NodeType(handle h,group_id gid):h(h),gid(gid){} virtual group_id memberOf()const{return gid;} virtual handle getHandle()const{return h;} private: group_id gid; handle h; }; struct NodeBaseHandleExtractor { typedef handle result_type; result_type operator()(const boost::shared_ptr<NodeBase>& x) { return x->getHandle(); } }; struct NodeBaseGroupIdExtractor { typedef group_id result_type; result_type operator()(const boost::shared_ptr<NodeBase>& x) { return x->memberOf(); } }; typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< NodeBaseHandleExtractor >, boost::multi_index::ordered_non_unique< NodeBaseGroupIdExtractor >
NodePtrSet;
int main() { NodePtrSet ns; typedef boost::shared_ptr<NodeBase> element_type; ns.insert(element_type(new NodeType(0,0))); ns.insert(element_type(new NodeType(1,0))); ns.insert(element_type(new NodeType(2,1))); return 0; } ******** END CODE ********