<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&#39;m really stuck on this one, so I&#39;m hoping someone can lend me a hand. �Basically, I&#39;m defining a templated multi-index-container to hold one piece of data along with two indexes to that data.�Next, I&#39;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&#39;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 (&quot;<span class="Apple-style-span" style="border-collapse: separate; font-family: arial; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; ">bimimapIterator2&quot; 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&#39;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&#39;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&lt;typename Key1,typename Key2, typename Data&gt;</div><div>struct bimultimap</div><div>{</div><div>��typedef boost::tuple&lt;Key1,Key2,Data&gt; value_type;</div>
<div><br></div><div>��typedef boost::multi_index_container&lt;</div><div>�� �value_type,</div><div>�� �indexed_by&lt;</div><div>�� � �ordered_non_unique&lt;</div><div>�� � � �tag&lt;index1&gt;,member&lt;value_type,Key1,&amp;value_type::first&gt; &gt;,</div>
<div>�� � �ordered_non_unique&lt;</div><div>�� � � �tag&lt;index2&gt;,member&lt;value_type,Key2,&amp;value_type::second&gt; &gt;</div><div>�� �&gt;</div><div>��&gt; 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&lt;typename Key1, typename Key2, typename Data&gt;</div><div>class concurrent_bimultimap</div><div>{</div><div>private:</div><div>�� �typename bimultimap&lt;Key1, Key2, Data&gt;::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&lt;Key1,Key2,Data&gt;::bimimap bimimapType;</div><div><span class="Apple-tab-span" style="white-space:pre">	</span>typedef typename bimultimap&lt;Key1,Key2,Data&gt;::bimimap::iterator bimimapIterator;</div>
<div><span class="Apple-tab-span" style="white-space:pre">	</span>typedef typename bimultimap&lt;Key1,Key2,Data&gt;::bimimap::index&lt;index2&gt;::type::iterator bimimapIterator2;</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">	</span>void insert(Key1 const&amp; key1, Key2 const&amp; key2, Data const&amp; 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&lt;Key1,Key2,Data&gt;::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 &quot;pop&quot; thread for short durations in burst situations. That&#39;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&amp; key1, Data&amp; 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-&gt;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&amp; key2, Data&amp; 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&lt;index2&gt;().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&lt;index2&gt;().end()) {</div><div><span class="Apple-tab-span" style="white-space:pre">			</span>data = itFindIt-&gt;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&#39;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>