Boost C++ Libraries: Ticket #9293: multi_index_container iterator needs base object size https://svn.boost.org/trac10/ticket/9293 <p> The reason this is a bug is because I cannot define 2 classes A&amp;B that will be stored in sequenced containers, and have A&amp;B each hold an iterator to the other's container. </p> <p> For example, this works: </p> <pre class="wiki">struct A; struct B { std::list&lt;A&gt;::iterator a_it; }; struct A { std::list&lt;B&gt;::iterator b_it; }; </pre><p> However, if I want to replace both lists with sequenced multi_index_containers, I can no longer compile it. </p> <p> The problem is that the iterator to a multi_index_container somehow calls sizeof on the stored class, so the forward declaration is not enough to compile. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9293 Trac 1.4.3 anonymous Wed, 23 Oct 2013 04:25:06 GMT attachment set https://svn.boost.org/trac10/ticket/9293 https://svn.boost.org/trac10/ticket/9293 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cpp</span> </li> </ul> <p> use case demonstration </p> Ticket anonymous Wed, 23 Oct 2013 04:30:40 GMT <link>https://svn.boost.org/trac10/ticket/9293#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9293#comment:1</guid> <description> <p> I don't have the latest boost installed. If you do, please compile the attached file and let me know if it works. For me, <code>g++ -std=c++0x -c test.c</code> fails, but it works with <code>-D USE_LIST</code>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joaquín M López Muñoz</dc:creator> <pubDate>Wed, 23 Oct 2013 06:12:21 GMT</pubDate> <title>status, type changed; resolution set https://svn.boost.org/trac10/ticket/9293#comment:2 https://svn.boost.org/trac10/ticket/9293#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Feature Requests</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> Hi, </p> <p> The reason your example fails to compile is that <code>multi_index_container</code> does not work on so-called incomplete types, i.e. it needs to know the size of the element type at instantiation time. This is not a bug per se, although the ability to work with incomplete types is of course a desireable one. </p> <p> Unfortunately I don't expect adding this capability any time soon as it needs some heavy refactoring I don't have currently the time for. Maybe you can replace your code with </p> <pre class="wiki">struct A; struct B { const A* a_p; }; struct A { const B* b_p; }; </pre><p> and use <code>iterator_to</code> to retrieve an iterator from a pointer when needed: </p> <p> <a href="http://www.boost.org/libs/multi_index/doc/tutorial/indices.html#iterator_to">http://www.boost.org/libs/multi_index/doc/tutorial/indices.html#iterator_to</a> </p> <p> Let me know if that works for you. </p> <p> </p> Ticket anonymous Wed, 23 Oct 2013 14:38:49 GMT type changed https://svn.boost.org/trac10/ticket/9293#comment:3 https://svn.boost.org/trac10/ticket/9293#comment:3 <ul> <li><strong>type</strong> <span class="trac-field-old">Feature Requests</span> → <span class="trac-field-new">Bugs</span> </li> </ul> <p> I understand, I didn't know about the completeness requirement, I thought I could just blindly replace std::list. </p> <p> Now I wonder, how is iterator_to implemented? Is there a hidden index, indexed by address? </p> Ticket Joaquín M López Muñoz Wed, 23 Oct 2013 15:29:44 GMT <link>https://svn.boost.org/trac10/ticket/9293#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9293#comment:4</guid> <description> <p> <em>I understand, I didn't know about the completeness requirement, I thought I could just blindly replace std::list.</em> </p> <p> In fact, if my memory serves me well there's no standard requirement that <code>std::list</code> can be instantiated with incomplete types, you happen to be using an stdlib implementation providing this nice-to-have feature. </p> <p> <em>Now I wonder, how is iterator_to implemented? Is there a hidden index, indexed by address?</em> </p> <p> There's no black magic here. <code>iterator_to</code> is used in the following context: </p> <pre class="wiki">iterator it=c.iterator_to(*p); </pre><p> So, you are providing the function with the node <em>and</em> the container it belongs to, this is all the info required to construct the iterator (not in a general case, but it happens to be so in Boost.<a class="missing wiki">MultiIndex</a>.) </p> </description> <category>Ticket</category> </item> </channel> </rss>