<br><div><br></div><div><span class="Apple-style-span" style="font-family: verdana; border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Hi,�<br><br>I'm really stuck on this one, so I'm hoping someone can lend me a hand. �Basically, I'm defining a templated multi-index-container to hold one piece of data along with two indexes to that data.�Next, I'm wrapping that in another templated class that will handle concurrent access to that structure.</span></div> <div><font class="Apple-style-span" face="verdana"><span class="Apple-style-span" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></font></div><div> <font class="Apple-style-span" face="verdana"><span class="Apple-style-span" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">My problem is that I'm having trouble figuring out how to define a type that will give me an interator on the 2nd index of the multi-index-container ("<span class="Apple-style-span" style="border-collapse: separate; font-family: arial; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; ">bimimapIterator2" below).</span></span></font></div> <div><font class="Apple-style-span" face="verdana"><span class="Apple-style-span" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></font></div><div> <span class="Apple-style-span" style="font-family: verdana; border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">I'm basing this on the Boost multi-index-container example here: �<span class="Apple-style-span" style="border-collapse: separate; font-family: arial; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><a href="http://www.boost.org/doc/libs/1_39_0/libs/multi_index/example/bimap.cpp">http://www.boost.org/doc/libs/1_39_0/libs/multi_index/example/bimap.cpp</a><span class="Apple-style-span" style="font-family: verdana; border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "></span></span></span></div> <div><font class="Apple-style-span" face="verdana"><span class="Apple-style-span" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></font></div><div> <span class="Apple-style-span" style="font-family: verdana; border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><span class="Apple-style-span" style="font-family: verdana; border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Here's what I have...�</span></span></span></div> <div><span class="Apple-style-span" style="font-family: verdana; border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br>//********************************************************************�<br> </span></div><div><font class="Apple-style-span" face="verdana"><span class="Apple-style-span" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">// � �multi-index-container</span></font></div> <div><font class="Apple-style-span" face="verdana"><span class="Apple-style-span" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">//********************************************************************</span></font></div> <div><br></div><div><div>struct index1{};</div><div>struct index2{};</div><div><br></div><div>template<typename Key1,typename Key2, typename Data></div><div>struct bimultimap</div><div>{</div><div>��typedef boost::tuple<Key1,Key2,Data> value_type;</div> <div><br></div><div>��typedef boost::multi_index_container<</div><div>�� �value_type,</div><div>�� �indexed_by<</div><div>�� � �ordered_non_unique<</div><div>�� � � �tag<index1>,member<value_type,Key1,&value_type::first> >,</div> <div>�� � �ordered_non_unique<</div><div>�� � � �tag<index2>,member<value_type,Key2,&value_type::second> ></div><div>�� �></div><div>��> bimimap;</div><div><br></div><div>};</div><div><br></div> <div><br></div><div><div><span class="Apple-style-span" style="font-family: verdana; border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">//********************************************************************�<br> </span></div><div><font class="Apple-style-span" face="verdana"><span class="Apple-style-span" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// � �concurrent access class.</span></font></div> <div><font class="Apple-style-span" face="verdana"><span class="Apple-style-span" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">//********************************************************************</span></font></div> </div><div><br></div><div>template<typename Key1, typename Key2, typename Data></div><div>class concurrent_bimultimap</div><div>{</div><div>private:</div><div>�� �typename bimultimap<Key1, Key2, Data>::bimimap � �the_bimultimap;</div> <div>�� �mutable boost::mutex � � the_mutex;</div><div>�� �boost::condition_variable � � the_condition_variable;</div><div><br></div><div>public:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef typename bimultimap<Key1,Key2,Data>::bimimap bimimapType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef typename bimultimap<Key1,Key2,Data>::bimimap::iterator bimimapIterator;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef typename bimultimap<Key1,Key2,Data>::bimimap::index<index2>::type::iterator bimimapIterator2;</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>void insert(Key1 const& key1, Key2 const& key2, Data const& data)</div> <div><span class="Apple-tab-span" style="white-space: pre; "> </span>{</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span><span class="Apple-tab-span" style="white-space: pre; "> </span>boost::mutex::scoped_lock lock(the_mutex);</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span><span class="Apple-tab-span" style="white-space: pre; "> </span>the_bimultimap.insert( bimultimap<Key1,Key2,Data>::bimimap::value_type(key1,key2,data) );</div> <div><br></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span><span class="Apple-tab-span" style="white-space: pre; "> </span>lock.unlock();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Note: because we unlock above and notify below, we can starve the "pop" thread for short durations in burst situations. That's ok so far.</div> <div><span class="Apple-tab-span" style="white-space: pre; "> </span><span class="Apple-tab-span" style="white-space: pre; "> </span>the_condition_variable.notify_one();</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>}</div> <div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>bool findKey1(Key1& key1, Data& data)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>boost::mutex::scoped_lock lock(the_mutex);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>bimimapIterator itFindIt = the_bimultimap.find(key1);</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>if (itFindIt != the_bimultimap.end()) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>data = itFindIt->third;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return true;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>else return false;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>bool findKey2(Key2& key2, Data& data)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>boost::mutex::scoped_lock lock(the_mutex);</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span><span class="Apple-tab-span" style="white-space: pre; "> </span>bimimapIterator2 itFindIt = the_bimultimap.get<index2>().find(key2);</div> <div><br></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span><span class="Apple-tab-span" style="white-space: pre; "> </span>if (itFindIt != the_bimultimap.get<index2>().end()) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>data = itFindIt->third;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>return true;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>else return false;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>..... there's more but this gives the essence of the problem ....�</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><br></div><div>};</div><div><br></div></div>