Re: [Boost-bugs] [Boost C++ Libraries] #5559: interval_set works not correct with custom compare function

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5559: interval_set works not correct with custom compare function
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-05-24 13:27:59


#5559: interval_set works not correct with custom compare function
------------------------------+---------------------------------------------
  Reporter: denis@… | Owner: jofaber
      Type: Bugs | Status: new
 Milestone: Boost 1.47.0 | Component: ICL
   Version: Boost 1.46.1 | Severity: Problem
Resolution: | Keywords:
------------------------------+---------------------------------------------

Comment (by denis@…):

 This can be worked around this way
 {{{
 #include <iostream>
 #include <assert.h>
 #include <boost/cstdint.hpp>
 #include <boost/icl/interval_set.hpp>

 class rint {
   boost::uint32_t i_;
 public:
   rint(int i=0) : i_(i) {}
   operator boost::uint32_t() const { return i_; }
   const rint& operator++() { ++i_; return *this; }
   const rint& operator--() { --i_; return *this; }
   bool operator <(rint r) const { return i_ < r.i_; }
   bool operator >(rint r) const { return i_ > r.i_; }
 };
 namespace boost{ namespace icl {
   template <> inline rint succ(rint x) { return --x; }
   template <> inline rint pred(rint x) { return ++x; }
 }}


 int main() {
   typedef boost::icl::interval_set<rint,
 ICL_COMPARE_INSTANCE(std::greater, rint)> Set;

   Set q1( Set::interval_type::closed(UINT32_MAX, 0) );
   Set q2( Set::interval_type::closed(1000, 100) );
   Set q3( Set::interval_type::closed(1, 1) );
   Set q4( Set::interval_type::closed(1, 0) );
   Set q5( Set::interval_type::closed(0, 0) );

   std::cout << q1 << " + " << q2 << " = " << (q1+q2) << std::endl; // ok
   std::cout << q1 << " + " << q3 << " = " << (q1+q3) << std::endl; // ok
   std::cout << q1 << " + " << q4 << " = " << (q1+q4) << std::endl; // ok
   std::cout << q1 << " + " << q5 << " = " << (q1+q5) << std::endl; // ok

   assert(q1 == q1+q2);
   assert(q1 == q1+q3);
   assert(q1 == q1+q4);
   assert(q1 == q1+q5);
 }
 }}}
 It is a bit strange, that Compare is settable per-container while succ()
 and pred() is settable per-type.
 discrete_interval needs all 3 function be performable on its domain and
 all of them to be consistent.
 Thus, per-type defined succ() and pred() give no chance for Compare to be
 chosen freely per-container. If succ() does increment then Compare has to
 be std::less, if succ() does decrement then Compare has to be
 std::greater, etc

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5559#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC