|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71351 - in sandbox/icl/boost/icl: . concept type_traits
From: afojgo_at_[hidden]
Date: 2011-04-17 07:50:51
Author: jofaber
Date: 2011-04-17 07:50:50 EDT (Sun, 17 Apr 2011)
New Revision: 71351
URL: http://svn.boost.org/trac/boost/changeset/71351
Log:
Bugfix: ticket_5482
Added:
sandbox/icl/boost/icl/type_traits/is_increasing.hpp
- copied unchanged from r71328, /trunk/boost/icl/type_traits/is_increasing.hpp
Properties modified:
sandbox/icl/boost/icl/ (props changed)
Text files modified:
sandbox/icl/boost/icl/concept/interval.hpp | 96 +++++++++++++++++++++++++---------------
sandbox/icl/boost/icl/discrete_interval.hpp | 4
sandbox/icl/boost/icl/left_open_interval.hpp | 3
sandbox/icl/boost/icl/right_open_interval.hpp | 3
sandbox/icl/boost/icl/type_traits/succ_pred.hpp | 70 +++++++++++++++++++++++++++--
5 files changed, 131 insertions(+), 45 deletions(-)
Modified: sandbox/icl/boost/icl/concept/interval.hpp
==============================================================================
--- sandbox/icl/boost/icl/concept/interval.hpp (original)
+++ sandbox/icl/boost/icl/concept/interval.hpp 2011-04-17 07:50:50 EDT (Sun, 17 Apr 2011)
@@ -61,6 +61,26 @@
return !(domain_compare()(left, right)) && !(domain_compare()(right, left));
}
+template<class Type>
+inline typename enable_if< is_interval<Type>
+ , typename interval_traits<Type>::domain_type>::type
+domain_next(const typename interval_traits<Type>::domain_type value)
+{
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
+ return icl::successor<domain_type,domain_compare>::apply(value);
+}
+
+template<class Type>
+inline typename enable_if< is_interval<Type>
+ , typename interval_traits<Type>::domain_type>::type
+domain_prior(const typename interval_traits<Type>::domain_type value)
+{
+ typedef typename interval_traits<Type>::domain_type domain_type;
+ typedef typename interval_traits<Type>::domain_compare domain_compare;
+ return icl::predecessor<domain_type,domain_compare>::apply(value);
+}
+
//==============================================================================
//= Construct<Interval> singleton
//==============================================================================
@@ -74,7 +94,7 @@
singleton(const typename interval_traits<Type>::domain_type& value)
{
//ASSERT: This always creates an interval with exactly one element
- return interval_traits<Type>::construct(value, icl::succ(value));
+ return interval_traits<Type>::construct(value, domain_next<Type>(value));
}
template<class Type>
@@ -90,7 +110,7 @@
typedef typename interval_traits<Type>::domain_type domain_type;
BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(value) ));
- return interval_traits<Type>::construct(icl::pred(value), value);
+ return interval_traits<Type>::construct(domain_prior<Type>(value), value);
}
template<class Type>
@@ -101,7 +121,8 @@
typedef typename interval_traits<Type>::domain_type domain_type;
BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(value)));
- return interval_traits<Type>::construct(icl::pred(value), icl::succ(value));
+ return interval_traits<Type>::construct( domain_prior<Type>(value)
+ , domain_next<Type>(value));
}
template<class Type>
@@ -139,7 +160,7 @@
>::type
unit_trail(const typename interval_traits<Type>::domain_type& value)
{
- return interval_traits<Type>::construct(value, icl::succ(value));
+ return interval_traits<Type>::construct(value, domain_next<Type>(value));
}
template<class Type>
@@ -154,7 +175,7 @@
typedef typename interval_traits<Type>::domain_type domain_type;
BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(value) ));
- return interval_traits<Type>::construct(icl::pred(value), value);
+ return interval_traits<Type>::construct(domain_prior<Type>(value), value);
}
template<class Type>
@@ -169,7 +190,8 @@
typedef typename interval_traits<Type>::domain_type domain_type;
BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(value)));
- return interval_traits<Type>::construct(icl::pred(value), icl::succ(value));
+ return interval_traits<Type>::construct( domain_prior<Type>(value)
+ , domain_next<Type>(value));
}
template<class Type>
@@ -233,7 +255,7 @@
span(const typename interval_traits<Type>::domain_type& left,
const typename interval_traits<Type>::domain_type& right)
{
- if(interval_traits<Type>::domain_compare(left,right))
+ if(interval_traits<Type>::domain_compare()(left,right))
return construct<Type>(left, right);
else
return construct<Type>(right, left);
@@ -246,10 +268,10 @@
hull(const typename interval_traits<Type>::domain_type& left,
const typename interval_traits<Type>::domain_type& right)
{
- if(interval_traits<Type>::domain_compare(left,right))
- return construct<Type>(left, icl::succ(right));
+ if(interval_traits<Type>::domain_compare()(left,right))
+ return construct<Type>(left, domain_next<Type>(right));
else
- return construct<Type>(right, icl::succ(left));
+ return construct<Type>(right, domain_next<Type>(left));
}
template<class Type>
@@ -258,15 +280,15 @@
const typename interval_traits<Type>::domain_type& right)
{
typedef typename interval_traits<Type>::domain_type domain_type;
- if(interval_traits<Type>::domain_compare(left,right))
+ if(interval_traits<Type>::domain_compare()(left,right))
{
BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(left) ));
- return construct<Type>(icl::pred(left), right);
+ return construct<Type>(domain_prior<Type>(left), right);
}
else
{
BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(right) ));
- return construct<Type>(icl::pred(right), left);
+ return construct<Type>(domain_prior<Type>(right), left);
}
}
@@ -275,7 +297,7 @@
hull(const typename interval_traits<Type>::domain_type& left,
const typename interval_traits<Type>::domain_type& right)
{
- if(interval_traits<Type>::domain_compare(left,right))
+ if(interval_traits<Type>::domain_compare()(left,right))
return construct<Type>(left, right);
else
return construct<Type>(right, left);
@@ -287,15 +309,17 @@
const typename interval_traits<Type>::domain_type& right)
{
typedef typename interval_traits<Type>::domain_type domain_type;
- if(interval_traits<Type>::domain_compare(left,right))
+ if(interval_traits<Type>::domain_compare()(left,right))
{
BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value >::is_less_than(left) ));
- return construct<Type>(icl::pred(left), icl::succ(right));
+ 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) ));
- return construct<Type>(icl::pred(right), icl::succ(left));
+ return construct<Type>( domain_prior<Type>(right)
+ , domain_next<Type>(left));
}
}
@@ -304,7 +328,7 @@
hull(const typename interval_traits<Type>::domain_type& left,
const typename interval_traits<Type>::domain_type& right)
{
- if(interval_traits<Type>::domain_compare(left,right))
+ if(interval_traits<Type>::domain_compare()(left,right))
return construct<Type>(left, right, interval_bounds::closed());
else
return construct<Type>(right, left, interval_bounds::closed());
@@ -348,7 +372,7 @@
, typename interval_traits<Type>::domain_type>::type
first(const Type& object)
{
- return icl::succ(lower(object));
+ return domain_next<Type>(lower(object));
}
template<class Type>
@@ -357,8 +381,8 @@
first(const Type& object)
{
return is_left_closed(object.bounds()) ?
- lower(object) :
- icl::succ(lower(object));
+ lower(object) :
+ domain_next<Type>(lower(object));
}
//- last -----------------------------------------------------------------------
@@ -381,7 +405,7 @@
typedef typename interval_traits<Type>::domain_type domain_type;
BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value>
::is_less_than(upper(object)) ));
- return icl::pred(upper(object));
+ return domain_prior<Type>(upper(object));
}
template<class Type>
@@ -393,8 +417,8 @@
BOOST_ASSERT((numeric_minimum<domain_type, is_numeric<domain_type>::value>
::is_less_than_or(upper(object), is_right_closed(object.bounds())) ));
return is_right_closed(object.bounds()) ?
- upper(object) :
- icl::pred(upper(object));
+ upper(object) :
+ domain_prior<Type>(upper(object));
}
//- last_next ------------------------------------------------------------------
@@ -405,7 +429,7 @@
, typename interval_traits<Type>::domain_type>::type
last_next(const Type& object)
{
- return icl::succ(upper(object));
+ return domain_next<Type>(upper(object));
}
template<class Type>
@@ -425,8 +449,8 @@
last_next(const Type& object)
{
return is_right_closed(object.bounds()) ?
- icl::succ(upper(object)):
- upper(object) ;
+ domain_next<Type>(upper(object)):
+ upper(object) ;
}
//------------------------------------------------------------------------------
@@ -507,7 +531,7 @@
typename boost::enable_if<is_static_open<Type>, bool>::type
is_empty(const Type& object)
{
- return domain_less_equal<Type>(upper(object), icl::succ(lower(object)));
+ return domain_less_equal<Type>(upper(object), domain_next<Type>(lower(object)));
}
template<class Type>
@@ -517,7 +541,7 @@
if(object.bounds() == interval_bounds::closed())
return domain_less<Type>(upper(object), lower(object));
else if(object.bounds() == interval_bounds::open())
- return domain_less_equal<Type>(upper(object), icl::succ(lower(object)));
+ return domain_less_equal<Type>(upper(object), domain_next<Type>(lower(object)));
else
return domain_less_equal<Type>(upper(object), lower(object));
}
@@ -894,7 +918,7 @@
typename boost::enable_if<is_discrete_interval<Type>, bool>::type
touches(const Type& left, const Type& right)
{
- return domain_equal<Type>(icl::succ(last(left)), first(right));
+ return domain_equal<Type>(domain_next<Type>(last(left)), first(right));
}
template<class Type>
@@ -1100,7 +1124,7 @@
if(exclusive_less(left_minuend, right))
return right;
- return construct<Type>(icl::succ(upper(left_minuend)), upper(right));
+ return construct<Type>(domain_next<Type>(upper(left_minuend)), upper(right));
}
template<class Type>
@@ -1110,7 +1134,7 @@
if(exclusive_less(left_minuend, right))
return right;
- return construct<Type>(icl::pred(upper(left_minuend)), upper(right));
+ return construct<Type>(domain_prior<Type>(upper(left_minuend)), upper(right));
}
template<class Type>
@@ -1152,7 +1176,7 @@
else if(lower_less_equal(right_minuend, left))
return identity_element<Type>::value();
- return construct<Type>(lower(left), icl::pred(lower(right_minuend)));
+ return construct<Type>(lower(left), domain_prior<Type>(lower(right_minuend)));
}
template<class Type>
@@ -1162,7 +1186,7 @@
if(exclusive_less(left, right_minuend))
return left;
- return construct<Type>(lower(left), icl::succ(lower(right_minuend)));
+ return construct<Type>(lower(left), domain_next<Type>(lower(right_minuend)));
}
template<class Type>
@@ -1273,9 +1297,9 @@
if(icl::is_empty(left) || icl::is_empty(right))
return identity_element<Type>::value();
else if(exclusive_less(left, right))
- return construct<Type>(icl::succ(upper(left)), icl::pred(lower(right)));
+ return construct<Type>(domain_next<Type>(upper(left)), domain_prior<Type>(lower(right)));
else if(exclusive_less(right, left))
- return construct<Type>(icl::succ(upper(right)), icl::pred(lower(left)));
+ return construct<Type>(domain_next<Type>(upper(right)), domain_prior<Type>(lower(left)));
else
return identity_element<Type>::value();
}
Modified: sandbox/icl/boost/icl/discrete_interval.hpp
==============================================================================
--- sandbox/icl/boost/icl/discrete_interval.hpp (original)
+++ sandbox/icl/boost/icl/discrete_interval.hpp 2011-04-17 07:50:50 EDT (Sun, 17 Apr 2011)
@@ -72,10 +72,10 @@
domain_type upper()const { return _upb; }
interval_bounds bounds()const{ return _bounds; }
- static discrete_interval open (const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::open()); }
+ static discrete_interval open (const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::open()); }
static discrete_interval right_open(const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::right_open());}
static discrete_interval left_open (const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::left_open()); }
- static discrete_interval closed (const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::closed()); }
+ static discrete_interval closed (const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::closed()); }
private:
domain_type _lwb;
Modified: sandbox/icl/boost/icl/left_open_interval.hpp
==============================================================================
--- sandbox/icl/boost/icl/left_open_interval.hpp (original)
+++ sandbox/icl/boost/icl/left_open_interval.hpp 2011-04-17 07:50:50 EDT (Sun, 17 Apr 2011)
@@ -24,6 +24,7 @@
public:
typedef left_open_interval<DomainT,Compare> type;
typedef DomainT domain_type;
+ typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
public:
//==========================================================================
@@ -41,7 +42,7 @@
/** Constructor for a left-open singleton interval <tt>(val-1,val]</tt> */
explicit left_open_interval(const DomainT& val)
- : _lwb(icl::pred(val)), _upb(val)
+ : _lwb(predecessor<DomainT,domain_compare>::apply(val)), _upb(val)
{
BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
Modified: sandbox/icl/boost/icl/right_open_interval.hpp
==============================================================================
--- sandbox/icl/boost/icl/right_open_interval.hpp (original)
+++ sandbox/icl/boost/icl/right_open_interval.hpp 2011-04-17 07:50:50 EDT (Sun, 17 Apr 2011)
@@ -25,6 +25,7 @@
public:
typedef right_open_interval<DomainT,Compare> type;
typedef DomainT domain_type;
+ typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
public:
//==========================================================================
@@ -42,7 +43,7 @@
/** Constructor for a singleton interval <tt>[val,val+1)</tt> */
explicit right_open_interval(const DomainT& val)
- : _lwb(val), _upb(icl::succ(val))
+ : _lwb(val), _upb(icl::successor<DomainT,domain_compare>::apply(val))
{
BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
Modified: sandbox/icl/boost/icl/type_traits/succ_pred.hpp
==============================================================================
--- sandbox/icl/boost/icl/type_traits/succ_pred.hpp (original)
+++ sandbox/icl/boost/icl/type_traits/succ_pred.hpp 2011-04-17 07:50:50 EDT (Sun, 17 Apr 2011)
@@ -1,5 +1,5 @@
/*-----------------------------------------------------------------------------+
-Copyright (c) 2008-2009: Joachim Faulhaber
+Copyright (c) 2008-2011: Joachim Faulhaber
+------------------------------------------------------------------------------+
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENCE.txt or copy at
@@ -8,13 +8,73 @@
#ifndef BOOST_ICL_TYPE_TRAITS_SUCC_PRED_HPP_JOFA_080913
#define BOOST_ICL_TYPE_TRAITS_SUCC_PRED_HPP_JOFA_080913
+#include <boost/icl/type_traits/is_increasing.hpp>
+
namespace boost{ namespace icl
{
- template <class IncrementableT>
- inline static IncrementableT succ(IncrementableT x) { return ++x; }
+template <class IncrementableT>
+inline static IncrementableT succ(IncrementableT x) { return ++x; }
+
+template <class DecrementableT>
+inline static DecrementableT pred(DecrementableT x) { return --x; }
+
+namespace detail
+{
+ template <class DomainT, bool increasing = true>
+ struct successor;
- template <class DecrementableT>
- inline static DecrementableT pred(DecrementableT x) { return --x; }
+ template <class DomainT>
+ struct successor<DomainT, true>
+ {
+ typedef successor type;
+ inline static DomainT apply(DomainT value){ return ++value; }
+ };
+
+ template <class DomainT>
+ struct successor<DomainT, false>
+ {
+ typedef successor type;
+ inline static DomainT apply(DomainT value){ return --value; }
+ };
+
+ template <class DomainT, bool increasing = true>
+ struct predecessor;
+
+ template <class DomainT>
+ struct predecessor<DomainT, true>
+ {
+ typedef predecessor type;
+ inline static DomainT apply(DomainT value){ return --value; }
+ };
+
+ template <class DomainT>
+ struct predecessor<DomainT, false>
+ {
+ typedef predecessor type;
+ inline static DomainT apply(DomainT value){ return ++value; }
+ };
+} // namespace detail
+
+//------------------------------------------------------------------------------
+template <class DomainT, class Compare>
+struct successor
+{
+ inline static DomainT apply(DomainT value)
+ {
+ return detail::successor
+ <DomainT, is_increasing<DomainT,Compare>::value>::apply(value);
+ }
+};
+
+template <class DomainT, class Compare>
+struct predecessor
+{
+ inline static DomainT apply(DomainT value)
+ {
+ return detail::predecessor
+ <DomainT, is_increasing<DomainT,Compare>::value>::apply(value);
+ }
+};
}} // namespace boost icl
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