Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72158 - in trunk: boost/icl/concept boost/icl/type_traits libs/icl/test/fix_tickets_
From: afojgo_at_[hidden]
Date: 2011-05-25 11:28:08


Author: jofaber
Date: 2011-05-25 11:28:06 EDT (Wed, 25 May 2011)
New Revision: 72158
URL: http://svn.boost.org/trac/boost/changeset/72158

Log:
Bug fix for ticket 5559: Assertion for numeric_minimum failed for std::greater ordering.
Added a Compare-parameter and a partial specialization for struct template numeric_minimum.
Text files modified:
   trunk/boost/icl/concept/interval.hpp | 52 ++++++++++++++++++++++++++-------------
   trunk/boost/icl/type_traits/is_numeric.hpp | 20 +++++++++++---
   trunk/libs/icl/test/fix_tickets_/fix_tickets.cpp | 14 ++++++++++
   3 files changed, 63 insertions(+), 23 deletions(-)

Modified: trunk/boost/icl/concept/interval.hpp
==============================================================================
--- trunk/boost/icl/concept/interval.hpp (original)
+++ trunk/boost/icl/concept/interval.hpp 2011-05-25 11:28:06 EDT (Wed, 25 May 2011)
@@ -107,8 +107,10 @@
 singleton(const typename interval_traits<Type>::domain_type& value)
 {
     //ASSERT: This always creates an interval with exactly one element
- typedef typename interval_traits<Type>::domain_type domain_type;
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(value) ));
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
+ ::is_less_than(value) ));
 
     return interval_traits<Type>::construct(domain_prior<Type>(value), value);
 }
@@ -118,8 +120,10 @@
 singleton(const typename interval_traits<Type>::domain_type& value)
 {
     //ASSERT: This always creates an interval with exactly one element
- typedef typename interval_traits<Type>::domain_type domain_type;
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(value)));
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
+ ::is_less_than(value)));
 
     return interval_traits<Type>::construct( domain_prior<Type>(value)
                                            , domain_next<Type>(value));
@@ -172,8 +176,10 @@
>::type
 unit_trail(const typename interval_traits<Type>::domain_type& value)
 {
- typedef typename interval_traits<Type>::domain_type domain_type;
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(value) ));
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
+ ::is_less_than(value) ));
 
     return interval_traits<Type>::construct(domain_prior<Type>(value), value);
 }
@@ -187,8 +193,10 @@
>::type
 unit_trail(const typename interval_traits<Type>::domain_type& value)
 {
- typedef typename interval_traits<Type>::domain_type domain_type;
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(value)));
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
+ ::is_less_than(value)));
 
     return interval_traits<Type>::construct( domain_prior<Type>(value)
                                            , domain_next<Type>(value));
@@ -279,15 +287,18 @@
 hull(const typename interval_traits<Type>::domain_type& left,
      const typename interval_traits<Type>::domain_type& right)
 {
- typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
     if(interval_traits<Type>::domain_compare()(left,right))
     {
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(left) ));
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
+ ::is_less_than(left) ));
         return construct<Type>(domain_prior<Type>(left), right);
     }
     else
     {
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(right) ));
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
+ ::is_less_than(right) ));
         return construct<Type>(domain_prior<Type>(right), left);
     }
 }
@@ -308,16 +319,19 @@
 hull(const typename interval_traits<Type>::domain_type& left,
      const typename interval_traits<Type>::domain_type& right)
 {
- typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
     if(interval_traits<Type>::domain_compare()(left,right))
     {
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(left) ));
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
+ ::is_less_than(left) ));
         return construct<Type>( domain_prior<Type>(left)
                               , domain_next<Type>(right));
     }
     else
     {
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(right) ));
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
+ ::is_less_than(right) ));
         return construct<Type>( domain_prior<Type>(right)
                               , domain_next<Type>(left));
     }
@@ -402,8 +416,9 @@
          , typename interval_traits<Type>::domain_type>::type
 last(const Type& object)
 {
- typedef typename interval_traits<Type>::domain_type domain_type;
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value>
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
                                  ::is_less_than(upper(object)) ));
     return domain_prior<Type>(upper(object));
 }
@@ -413,8 +428,9 @@
                           typename interval_traits<Type>::domain_type>::type
 last(const Type& object)
 {
- typedef typename interval_traits<Type>::domain_type domain_type;
- BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value>
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
+ BOOST_ASSERT((numeric_minimum<domain_type, domain_compare, is_numeric<domain_type>::value>
                                  ::is_less_than_or(upper(object), is_right_closed(object.bounds())) ));
     return is_right_closed(object.bounds()) ?
                                   upper(object) :

Modified: trunk/boost/icl/type_traits/is_numeric.hpp
==============================================================================
--- trunk/boost/icl/type_traits/is_numeric.hpp (original)
+++ trunk/boost/icl/type_traits/is_numeric.hpp 2011-05-25 11:28:06 EDT (Wed, 25 May 2011)
@@ -54,20 +54,30 @@
 };
 
 //--------------------------------------------------------------------------
-template<class Type, bool Enable = false> struct numeric_minimum;
+//CL template<class Type, class Compare, bool Enable = false> struct numeric_minimum;
 
-template<class Type>
-struct numeric_minimum<Type, false>
+template<class Type, class Compare, bool Enable = false>
+struct numeric_minimum
 {
     static bool is_less_than(Type){ return true; }
     static bool is_less_than_or(Type, bool){ return true; }
 };
 
 template<class Type>
-struct numeric_minimum<Type, true>
+struct numeric_minimum<Type, std::less<Type>, true>
+{
+ static bool is_less_than(Type value)
+ { return std::less<Type>()((std::numeric_limits<Type>::min)(), value); }
+
+ static bool is_less_than_or(Type value, bool cond)
+ { return cond || is_less_than(value); }
+};
+
+template<class Type>
+struct numeric_minimum<Type, std::greater<Type>, true>
 {
     static bool is_less_than(Type value)
- { return (std::numeric_limits<Type>::min)() < value; }
+ { return std::greater<Type>()((std::numeric_limits<Type>::max)(), value); }
 
     static bool is_less_than_or(Type value, bool cond)
     { return cond || is_less_than(value); }

Modified: trunk/libs/icl/test/fix_tickets_/fix_tickets.cpp
==============================================================================
--- trunk/libs/icl/test/fix_tickets_/fix_tickets.cpp (original)
+++ trunk/libs/icl/test/fix_tickets_/fix_tickets.cpp 2011-05-25 11:28:06 EDT (Wed, 25 May 2011)
@@ -40,3 +40,17 @@
     BOOST_CHECK_EQUAL(m2.iterative_size(), 1);
 }
 
+
+#include <boost/cstdint.hpp>
+BOOST_AUTO_TEST_CASE(ticket_5559_Denis)
+{
+ //Submitted by Denis
+ typedef boost::icl::interval_set<boost::uint32_t, std::greater> Set;
+ const uint32_t ui32_max = (std::numeric_limits<uint32_t>::max)();
+
+ Set q1( Set::interval_type::closed(ui32_max, 0) );
+ Set q5( Set::interval_type::closed(0, 0) );
+
+ BOOST_CHECK_EQUAL(q1, q1+q5);
+}
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk