Boost C++ Libraries: Ticket #11609: circular_buffer erroneously invalidates reverse_iterator at pop_back in debug mode https://svn.boost.org/trac10/ticket/11609 <p> The circular_buffer container offers reverse iterators. Using one so that it points to the second-to-last element would in theory allow to pop_back() the last element without causing problems with that iterator. However, apparently pop_back() invalidates those reverse iterators even though they wouldn't cause problems, as if the debug_iterator_registry in boost/circular_buffer/debug.hpp is working correctly only for forward iterators but not for backward iterators. </p> <p> Example code that works fine without debug mode, but will run into a failed assertion in debug mode: </p> <pre class="wiki">#define BOOST_CB_ENABLE_DEBUG #include &lt;boost/circular_buffer.hpp&gt; #include &lt;iostream&gt; int main(int /*argc*/, char** /*argv*/) { typedef boost::circular_buffer&lt;int&gt; CircBuffer; CircBuffer testBuffer(2); testBuffer.push_back(4); testBuffer.push_back(8); CircBuffer::const_reverse_iterator bufIter = testBuffer.rbegin(); std::cout &lt;&lt; "element at rbegin=" &lt;&lt; *bufIter &lt;&lt; std::endl; // prints "=8" correctly ++bufIter; std::cout &lt;&lt; "element after ++=" &lt;&lt; *bufIter &lt;&lt; std::endl; // prints "=4" correctly testBuffer.pop_back(); std::cout &lt;&lt; "elem=" &lt;&lt; *bufIter &lt;&lt; std::endl; // ERROR: Causes "Assertion `is_valid(m_buff)' failed." } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11609 Trac 1.4.3 christian.stimming@… Tue, 01 Sep 2015 15:55:58 GMT <link>https://svn.boost.org/trac10/ticket/11609#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11609#comment:1</guid> <description> <p> Sorry, here the code again in readable form: </p> <pre class="wiki">#define BOOST_CB_ENABLE_DEBUG #include &lt;boost/circular_buffer.hpp&gt; #include &lt;iostream&gt; using namespace std; int main(int /*argc*/, char /*argv*/) { typedef boost::circular_buffer&lt;int&gt; CircBuffer; CircBuffer buffer(2); buffer.push_back(4); buffer.push_back(8); CircBuffer::const_reverse_iterator iter = buffer.rbegin(); cout &lt;&lt; "elem=" &lt;&lt; *iter &lt;&lt; endl; // prints "=8" correctly ++iter; cout &lt;&lt; "elem=" &lt;&lt; *iter &lt;&lt; endl; // prints "=4" correctly buffer.pop_back(); // ERROR: invalidates the iterator cout &lt;&lt; "elem=" &lt;&lt; *iter &lt;&lt; endl; // ERROR: Causes "Assertion `is_valid(m_buff)' failed." instead of printing "=4" } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 02 Sep 2015 17:54:42 GMT</pubDate> <title>component, description changed; owner set https://svn.boost.org/trac10/ticket/11609#comment:2 https://svn.boost.org/trac10/ticket/11609#comment:2 <ul> <li><strong>owner</strong> set to <span class="trac-author">Jan Gaspar</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">circular_buffer</span> </li> <li><strong>description</strong> modified (<a href="/trac10/ticket/11609?action=diff&amp;version=2">diff</a>) </li> </ul> Ticket