Boost C++ Libraries: Ticket #8069: Boost unordered_map iterator bug https://svn.boost.org/trac10/ticket/8069 <p> The documentation (<a href="http://www.boost.org/doc/libs/1_53_0/doc/html/boost/unordered_map.html">http://www.boost.org/doc/libs/1_53_0/doc/html/boost/unordered_map.html</a>) states that mapped_type&amp; operator[](key_type const&amp; k) function can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. </p> <p> In particular, this does not happen. I have written a simple test for this. I compare boost::unordered_map with std::tr1::unordered_map. The former does not guarantuees that iterators are still valid if the insert DOES NOT cause the load factor to be greater to or equal to the maximum load factor. </p> <p> I run tests with g++4.7.2 and boost 1.53. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8069 Trac 1.4.3 Karalis Apostolos <tolis@…> Fri, 15 Feb 2013 15:04:36 GMT attachment set https://svn.boost.org/trac10/ticket/8069 https://svn.boost.org/trac10/ticket/8069 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cpp</span> </li> </ul> Ticket viboes Fri, 15 Feb 2013 17:18:00 GMT component changed; owner set https://svn.boost.org/trac10/ticket/8069#comment:1 https://svn.boost.org/trac10/ticket/8069#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Daniel James</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">unordered</span> </li> </ul> Ticket Daniel James Fri, 15 Feb 2013 20:38:13 GMT <link>https://svn.boost.org/trac10/ticket/8069#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8069#comment:2</guid> <description> <p> The iterator is still valid, it's pointing at '0' which is the last element in the container, so your loop only prints out that element. Try printing out all the elements and you can see that the '0' comes last. Remember that these are unordered containers, so there's no guarantee that they'll have any particular order. </p> </description> <category>Ticket</category> </item> <item> <author>Karalis Apostolos <tolis@…></author> <pubDate>Fri, 15 Feb 2013 23:40:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8069#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8069#comment:3</guid> <description> <p> Thanks for the reply. </p> <p> I don't expect unordered map (keys) following a specific order. I thought that if i insert into an unordered map (e.g int-&gt;int) the pairs 0-&gt;5, 4-&gt;3, 6-&gt;9, 2-&gt;0 and before the insert of the pair 6-&gt;9 take the iterator of map[4 ] then after the insertion of the last pair, i can print out map[4 ], map[6 ] and map[2 ] using the operator ++. This is very useful in case of large unordered maps and multithreading (one thread inserts/looksup elements and another one checks every x seconds (the next) y map's elements, not simultaneously). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Sat, 16 Feb 2013 00:09:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8069#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8069#comment:4</guid> <description> <p> You're assuming that the order of the elements in the container is the same as the insertion order. This is not the case. map<a class="changeset" href="https://svn.boost.org/trac10/changeset/6" title="New repository initialized by cvs2svn.">[6]</a> and map<a class="changeset" href="https://svn.boost.org/trac10/changeset/2" title="Add Boost Disclaimer">[2]</a> could just as easily appear before map<a class="changeset" href="https://svn.boost.org/trac10/changeset/4" title="Tweak disclaimer formatting, again">[4]</a> when iterating over the container and in fact, as Daniel stated, this is what is happening in your test case. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Sun, 17 Feb 2013 22:14:43 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8069#comment:5 https://svn.boost.org/trac10/ticket/8069#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> Ticket