Boost C++ Libraries: Ticket #5482: iterative_size() not the same for interval_maps using std::less and std::greater https://svn.boost.org/trac10/ticket/5482 <p> The assertion at the bottom fails. </p> <pre class="wiki">typedef interval_map&lt;int,int,partial_absorber,std::less&gt; m1_t; typedef interval_map&lt;int,int,partial_absorber,std::greater&gt; m2_t; m1_t m1; m2_t m2; m1.insert(make_pair(m1_t::interval_type(1), 20)); m1.insert(make_pair(m1_t::interval_type(2), 20)); m1.insert(make_pair(m1_t::interval_type(3), 20)); m2.insert(make_pair(m2_t::interval_type(1), 20)); m2.insert(make_pair(m2_t::interval_type(2), 20)); m2.insert(make_pair(m2_t::interval_type(3), 20)); Assert::IsTrue(m1.iterative_size() == m2.iterative_size()); </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5482 Trac 1.4.3 Joachim Faulhaber Sat, 16 Apr 2011 10:02:15 GMT <link>https://svn.boost.org/trac10/ticket/5482#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5482#comment:1</guid> <description> <p> Hi, </p> <p> thank you for this interesting bug report. In generic programming we may forget to vary template paramteres in tests, specifically if we have many of them ;) The problem you have found has to do with interval initialization of singleton intervals [x, ++x), because x &lt; ++x is only valid with std::less and not with std::greater. </p> <p> Replying to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5482" title="#5482: Bugs: iterative_size() not the same for interval_maps using std::less and ... (closed: fixed)">boicotinho@…</a>: </p> <blockquote class="citation"> <p> The assertion at the bottom fails. </p> <pre class="wiki">typedef interval_map&lt;int,int,partial_absorber,std::less&gt; m1_t; typedef interval_map&lt;int,int,partial_absorber,std::greater&gt; m2_t; m1_t m1; m2_t m2; m1.insert(make_pair(m1_t::interval_type(1), 20)); m1.insert(make_pair(m1_t::interval_type(2), 20)); m1.insert(make_pair(m1_t::interval_type(3), 20)); m2.insert(make_pair(m2_t::interval_type(1), 20)); m2.insert(make_pair(m2_t::interval_type(2), 20)); m2.insert(make_pair(m2_t::interval_type(3), 20)); Assert::IsTrue(m1.iterative_size() == m2.iterative_size()); </pre></blockquote> <p> I will fix that bug for the general case ASAP. For the time being, you could use a work around that seems to work. Construct intervals explicitly with two values: </p> <pre class="wiki">typedef interval_map&lt;int,int,partial_absorber,std::less&gt; m1_t; typedef interval_map&lt;int,int,partial_absorber,std::greater&gt; m2_t; m1_t m1; m2_t m2; m1.insert(make_pair(m1_t::interval_type(1), 20)); m1.insert(make_pair(m1_t::interval_type(2), 20)); m1.insert(make_pair(m1_t::interval_type(3), 20)); m2.insert(make_pair(m2_t::interval_type(3,2), 20)); //Singleton intervals m2.insert(make_pair(m2_t::interval_type(2,1), 20)); //constructed explicitly m2.insert(make_pair(m2_t::interval_type(1,0), 20)); //with std::greater ordering BOOST_CHECK_EQUAL(m1.iterative_size(), m2.iterative_size()); </pre><p> Alas I can't guarantee that there aren't more problems lurking with std::greater, since as you detected, I haven't tested these cases carefully enough yet. </p> <p> Best regards, Joachim </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joachim Faulhaber</dc:creator> <pubDate>Sat, 16 Apr 2011 10:04:59 GMT</pubDate> <title>keywords, status, milestone changed https://svn.boost.org/trac10/ticket/5482#comment:2 https://svn.boost.org/trac10/ticket/5482#comment:2 <ul> <li><strong>keywords</strong> ordering added </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.47.0</span> </li> </ul> Ticket anonymous Sun, 17 Apr 2011 09:53:37 GMT <link>https://svn.boost.org/trac10/ticket/5482#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5482#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5482#comment:2" title="Comment 2">jofaber</a>: </p> <p> Thank you for looking into this - I really like this ICL of yours and use it a lot :) </p> <p> FYI It seems that your workaround works - but if I insert the intervals in another order for m2, then m2.find() fails while m1.find() still works. </p> <p> In the meanwhile I am using std::less but representing the data with negative numbers instead. </p> <p> The reason I wanted to use std::greater is because I would like find() to start from the highest interval given a range. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joachim Faulhaber</dc:creator> <pubDate>Sun, 17 Apr 2011 16:50:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5482#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5482#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5482#comment:3" title="Comment 3">anonymous</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5482#comment:2" title="Comment 2">jofaber</a>: </p> <p> Thank you for looking into this - I really like this ICL of yours and use it a lot :) </p> </blockquote> <p> That's nice to hear. For me it is good to have users who are challenging the library or use it creative ways, so we can detect flaws and improve the code. </p> <blockquote class="citation"> <p> FYI It seems that your workaround works - but if I insert the intervals in another order for m2, then m2.find() fails while m1.find() still works. </p> </blockquote> <p> True, I suspected you'd find some more problems using std::greater. I have found and fixed more inconsistencies between compare-order and incrementation/decrementation that caused these program failures and committed the improved code to the boost/trunk. You might want to get a copy of that code if you like. I am still doing some testing though before closing the ticket. </p> <blockquote class="citation"> <p> In the meanwhile I am using std::less but representing the data with negative numbers instead. </p> <p> The reason I wanted to use std::greater is because I would like find() to start from the highest interval given a range. </p> </blockquote> <p> To find the last interval that overlaps a given interval <code>I</code> you could use <code>it = m.upper_bound(I)</code>, which yields an iterator to the first interval that is greater than I and then decrement the iterator <code>it</code> once. </p> <p> Cheers, Joachim </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joachim Faulhaber</dc:creator> <pubDate>Mon, 18 Apr 2011 13:42:37 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5482#comment:5 https://svn.boost.org/trac10/ticket/5482#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket denis@… Tue, 24 May 2011 13:31:10 GMT <link>https://svn.boost.org/trac10/ticket/5482#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5482#comment:6</guid> <description> <p> related ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5559" title="#5559: Bugs: interval_set works not correct with custom compare function (closed: fixed)">#5559</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>