Boost logo

Boost Users :

Subject: [Boost-users] Multi Index Container - find() not working with std::string, kind of stuck...
From: Steve Hibbert (hiblet_at_[hidden])
Date: 2011-07-08 12:54:28


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
  < 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:

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,


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at