Multi Index Container - find() not working with std::string, kind of stuck...

Hi, I've hit a snag with the Boost Multi Index Container, and I'd really appreciate some help. I've set up a container and I am using it to store shared pointers to custom objects. The custom objects are just data collections effectively, including std::strings, chars, ints etc. The problem is that when I try to find a string in the MIC, the find function sometimes succeeds, and sometimes returns the same iterator as .end(), indicating a failure to find. Yet, if I iterate through the container testing the strings, the string is always found. I've done something wrong, but I do not know what it is. Here's the container definition... typedef boost::multi_index::multi_index_container < spExchOrder, boost::multi_index::indexed_by < boost::multi_index::ordered_unique // 0 index - shared pointer index < boost::multi_index::identity<spExchOrder> > , boost::multi_index::ordered_unique // 1 index - Exchange ID eg "ORD-WIDGET-Timestamp" < boost::multi_index::const_mem_fun< FC::ExchOrder, std::string, &FC::ExchOrder::ID > > , boost::multi_index::ordered_unique // 2 index - OrigDetails eg "CLIENTA|ORDER00123" < boost::multi_index::const_mem_fun< FC::ExchOrder, std::string, &FC::ExchOrder::origDetails > >
OrderReg;
The spExchOrder typedef is just a std::tr1 shared pointer to an FC::ExchOrder object. This object has member functions that return the ID and origDetails member variable data as std::string type. Both are guaranteed unique. I'm searching the MIC using this kind of code: std::string sExchID = "Passed in Exchange ID"; OrderReg::nth_index<1>::type::iterator i = m_regOrders.get<1>().find( sExchID ); OrderReg::nth_index<1>::type::iterator iEnd = m_regOrders.get<1>().end(); if ( i != iEnd ) { // Found, do what needs to be done } I add shared pointers to the MIC like this: m_regOrders.insert(spOrder); When needed, shared pointers are deleted like this: OrderReg::nth_index<0>::type& indexSP = m_regOrders.get<0>(); iDelCount = indexSP.erase(spOrder); Any help with this would be greatly appreciated. Multi Index Containers have sorted out a number of problems for me, but I can't get past this issue. Thanks in advance, Steve

I've found the problem. I broke the constancy rule on the container, like a true noob. Objects were being added to the container with a temporary ExchID, and then subsequently the ExchID's for each object were updated, making the ExchID index corrupt. Whenever I listed the container objects, they looked fine, and the index looked OK. The corruption gave me a 50-50 hit rate on finding objects using that index, which had me confused to say the least. And all it took was a couple of days to discover. -- View this message in context: http://boost.2283326.n4.nabble.com/Multi-Index-Container-find-not-working-wi... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (1)
-
Steve Hibbert