Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50663 - in sandbox/itl: boost/itl boost/itl/type_traits libs/itl/test libs/itl/test/test_interval_map libs/itl/test/test_interval_map_mixed
From: afojgo_at_[hidden]
Date: 2009-01-18 17:54:24


Author: jofaber
Date: 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
New Revision: 50663
URL: http://svn.boost.org/trac/boost/changeset/50663

Log:
Refactored. Added itl global .+. operators using enable_if. Stable {msvc-9.0, partly congcc-4.3-a7}

Added:
   sandbox/itl/boost/itl/operators.hpp (contents, props changed)
   sandbox/itl/boost/itl/type_traits/is_combinable.hpp (contents, props changed)
Text files modified:
   sandbox/itl/boost/itl/interval_base_map.hpp | 5 -
   sandbox/itl/boost/itl/interval_base_set.hpp | 5 -
   sandbox/itl/boost/itl/interval_map.hpp | 8 ++
   sandbox/itl/boost/itl/interval_maps.hpp | 48 +++++++++++++++++-
   sandbox/itl/boost/itl/separate_interval_set.hpp | 2
   sandbox/itl/boost/itl/split_interval_set.hpp | 2
   sandbox/itl/libs/itl/test/test_interval_map/test_interval_map.cpp | 1
   sandbox/itl/libs/itl/test/test_interval_map/test_interval_map_shared.cpp | 4 +
   sandbox/itl/libs/itl/test/test_interval_map_mixed/test_interval_map_mixed.cpp | 1
   sandbox/itl/libs/itl/test/test_interval_map_shared.hpp | 101 ++++++++++++++++++++++++++++++++++++++++
   10 files changed, 161 insertions(+), 16 deletions(-)

Modified: sandbox/itl/boost/itl/interval_base_map.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval_base_map.hpp (original)
+++ sandbox/itl/boost/itl/interval_base_map.hpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -251,10 +251,7 @@
     /// Assignment operator
     interval_base_map& operator = (const interval_base_map& src)
     {
- if(this==&src)
- return *this;
-
- that()->assign(src);
+ if(this!=&src) that()->assign(src);
         return *this;
     }
 

Modified: sandbox/itl/boost/itl/interval_base_set.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval_base_set.hpp (original)
+++ sandbox/itl/boost/itl/interval_base_set.hpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -184,10 +184,7 @@
     /// Assignment operator
     interval_base_set& operator = (const interval_base_set& src)
     {
- if(this==&src)
- return *this;
-
- that()->assign(src);
+ if(this!=&src) that()->assign(src);
         return *this;
     }
 

Modified: sandbox/itl/boost/itl/interval_map.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval_map.hpp (original)
+++ sandbox/itl/boost/itl/interval_map.hpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -21,6 +21,11 @@
 namespace boost{namespace itl
 {
 
+template<class DomainT, class CodomainT, class Traits,
+ ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section,
+ template<class,ITL_COMPARE>class Interval, ITL_ALLOC Alloc>
+class split_interval_map;
+
 /// implements a map as a map of intervals - on insertion overlapping intervals are split and associated values are combined.
 /**
     Template-class <b>interval_map</b>
@@ -120,7 +125,8 @@
 {
 public:
     typedef Traits traits;
- typedef interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> type;
+ typedef interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> type;
+ typedef split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> split_type;
     typedef type joint_type;
     typedef interval_base_map <interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>,
                                DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> base_type;

Modified: sandbox/itl/boost/itl/interval_maps.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval_maps.hpp (original)
+++ sandbox/itl/boost/itl/interval_maps.hpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -10,6 +10,7 @@
 
 #include <boost/itl/interval_base_map.hpp>
 #include <boost/itl/interval_map_algo.hpp>
+#include <boost/itl/operators.hpp>
 
 namespace boost{namespace itl
 {
@@ -51,6 +52,7 @@
     return object;
 }
 
+/*CL?
 template
 <
     class SubType, class DomainT, class CodomainT, class Traits,
@@ -72,6 +74,7 @@
         typedef interval_base_map<SubType,DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> ObjectT;
         return ObjectT(object) += operand;
 }
+*/
 //-----------------------------------------------------------------------------
 
 template
@@ -100,10 +103,10 @@
     return object;
 }
 
+/*CL?
 template
 <
- class DomainT, class CodomainT, class Traits,
-
+ class DomainT, class CodomainT, class Traits,
     ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, template<class,ITL_COMPARE>class Interval, ITL_ALLOC Alloc,
     template
     <
@@ -122,13 +125,13 @@
         typedef IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> ObjectT;
         return ObjectT(object) += operand;
 }
+*/
 //-----------------------------------------------------------------------------
 
 //--- value_type --------------------------------------------------------------
 template
 <
     class DomainT, class CodomainT, class Traits,
-
     ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, template<class,ITL_COMPARE>class Interval, ITL_ALLOC Alloc,
     template
     <
@@ -148,10 +151,10 @@
     return object.add(operand);
 }
 
+/*CL
 template
 <
     class DomainT, class CodomainT, class Traits,
-
     ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, template<class,ITL_COMPARE>class Interval, ITL_ALLOC Alloc,
     template
     <
@@ -163,13 +166,46 @@
 IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
 operator +
 (
- const IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>& object,
+ const IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>& object,
     const typename IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>::value_type& operand
 )
 {
         typedef IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> ObjectT;
         return ObjectT(object) += operand;
 }
+
+template
+<
+ class DomainT, class CodomainT, class Traits,
+ ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, template<class,ITL_COMPARE>class Interval, ITL_ALLOC Alloc,
+ template
+ <
+ class, class, class,
+ ITL_COMPARE, ITL_COMBINE, ITL_SECTION, template<class,ITL_COMPARE>class, ITL_ALLOC
+ >
+ class IntervalMap
+>
+IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
+operator +
+(
+ const typename IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>::value_type& operand,
+ const IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>& object
+)
+{
+ typedef IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> ObjectT;
+ return ObjectT(object) += operand;
+}
+*/
+/*CL
+template<class ObjectT>
+ObjectT operator + (const ObjectT& object, const typename ObjectT::value_type& operand)
+{ return ObjectT(object) += operand; }
+
+template<class ObjectT>
+ObjectT operator + (const typename ObjectT::value_type& operand, const ObjectT& object)
+{ return ObjectT(object) += operand; }
+*/
+
 //-----------------------------------------------------------------------------
 
 //--- mapping_type ------------------------------------------------------------
@@ -209,6 +245,7 @@
     return object.add(operand);
 }
 
+/*
 template
 <
     class DomainT, class CodomainT, class Traits,
@@ -231,6 +268,7 @@
         typedef IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> ObjectT;
         return ObjectT(object) += operand;
 }
+*/
 //-----------------------------------------------------------------------------
 
 

Added: sandbox/itl/boost/itl/operators.hpp
==============================================================================
--- (empty file)
+++ sandbox/itl/boost/itl/operators.hpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -0,0 +1,78 @@
+/*----------------------------------------------------------------------------+
+Copyright (c) 2008-2008: Joachim Faulhaber
++-----------------------------------------------------------------------------+
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENCE.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
++----------------------------------------------------------------------------*/
+#ifndef __itl_operators_JOFA_090115_H__
+#define __itl_operators_JOFA_090115_H__
+
+#include <boost/utility/enable_if.hpp>
+#include <boost/itl/type_traits/is_combinable.hpp>
+
+namespace boost{namespace itl
+{
+
+
+template<class ObjectT, class OperandT>
+typename boost::enable_if<is_combinable<ObjectT, OperandT>, ObjectT>::type
+operator + (const ObjectT& object, const OperandT& operand)
+{ return ObjectT(object) += operand; }
+
+template<class ObjectT, class OperandT>
+typename boost::enable_if<is_combinable<ObjectT, OperandT>, ObjectT>::type
+operator + (const OperandT& operand, const ObjectT& object)
+{ return ObjectT(object) += operand; }
+
+template<class ObjectT>
+ObjectT operator + (const ObjectT& object, const ObjectT& operand)
+{ return ObjectT(object) += operand; }
+
+/*
+template<class ObjectT>
+ObjectT operator + (const ObjectT& object, const typename ObjectT::value_type& operand)
+{ return ObjectT(object) += operand; }
+
+template<class ObjectT>
+ObjectT operator + (const typename ObjectT::value_type& operand, const ObjectT& object)
+{ return ObjectT(object) += operand; }
+
+template<class ObjectT>
+ObjectT operator + (const ObjectT& object, const typename ObjectT::mapping_pair_type& operand)
+{ return ObjectT(object) += operand; }
+
+template<class ObjectT>
+ObjectT operator + (const typename ObjectT::mapping_pair_type& operand, const ObjectT& object)
+{ return ObjectT(object) += operand; }
+
+template<class ObjectT>
+ObjectT operator + (const ObjectT& object, const typename ObjectT::split_type& operand)
+{ return ObjectT(object) += operand; }
+
+template<class ObjectT>
+ObjectT operator + (const typename ObjectT::split_type& operand, const ObjectT& object)
+{ return ObjectT(object) += operand; }
+
+//template<class ObjectT>
+//ObjectT operator + (const ObjectT& object, const typename ObjectT::joint_type& operand)
+//{ return ObjectT(object) += operand; }
+//
+//template<class ObjectT>
+//ObjectT operator + (const typename ObjectT::joint_type& operand, const ObjectT& object)
+//{ return ObjectT(object) += operand; }
+
+template<class ObjectT>
+ObjectT operator + (const ObjectT& object, const typename ObjectT::separating_type& operand)
+{ return ObjectT(object) += operand; }
+
+template<class ObjectT>
+ObjectT operator + (const typename ObjectT::separating_type& operand, const ObjectT& object)
+{ return ObjectT(object) += operand; }
+*/
+
+}} // namespace itl boost
+
+#endif
+
+

Modified: sandbox/itl/boost/itl/separate_interval_set.hpp
==============================================================================
--- sandbox/itl/boost/itl/separate_interval_set.hpp (original)
+++ sandbox/itl/boost/itl/separate_interval_set.hpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -152,7 +152,7 @@
     template<class SubType>
     separate_interval_set& operator =
         (const interval_base_set<SubType,DomainT,Compare,Interval,Alloc>& src)
- { assign(src); return *this; }
+ { BOOST_ASSERT(this != &src); assign(src); return *this; }
 
     /// Assignment from a base interval_set.
     template<class SubType>

Modified: sandbox/itl/boost/itl/split_interval_set.hpp
==============================================================================
--- sandbox/itl/boost/itl/split_interval_set.hpp (original)
+++ sandbox/itl/boost/itl/split_interval_set.hpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -169,7 +169,7 @@
         template<class SubType>
         split_interval_set& operator =
             (const interval_base_set<SubType,DomainT,Compare,Interval,Alloc>& src)
- { assign(src); return *this; }
+ { BOOST_ASSERT(this != &src); assign(src); return *this; }
 
         /// Assignment from a base interval_set.
         template<class SubType>

Added: sandbox/itl/boost/itl/type_traits/is_combinable.hpp
==============================================================================
--- (empty file)
+++ sandbox/itl/boost/itl/type_traits/is_combinable.hpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -0,0 +1,44 @@
+/*----------------------------------------------------------------------------+
+Copyright (c) 2008-2008: Joachim Faulhaber
++-----------------------------------------------------------------------------+
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENCE.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
++----------------------------------------------------------------------------*/
+#ifndef __itl_is_combinable_JOFA_090115_H__
+#define __itl_is_combinable_JOFA_090115_H__
+
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/itl/type_traits/is_interval_splitter.hpp>
+
+namespace boost{namespace itl
+{
+
+template<class Type, class AssociateT>
+struct is_combinable;
+
+template<class Type>
+struct is_combinable<Type, typename Type::value_type> { enum{ value = true }; };
+template<class Type>
+struct is_combinable<Type, typename Type::mapping_pair_type>{ enum{ value = true }; };
+template<class Type>
+struct is_combinable<Type, typename Type::joint_type> { enum{ value = true }; };
+
+template<class Type>
+struct is_combinable<Type, typename Type::separate_type>
+{
+ enum{ value = is_interval_splitter<Type>::value };
+};
+
+template<class Type, class AssociateT>
+struct is_combinable
+{
+ enum{ value = false };
+};
+
+}} // namespace itl boost
+
+#endif
+
+

Modified: sandbox/itl/libs/itl/test/test_interval_map/test_interval_map.cpp
==============================================================================
--- sandbox/itl/libs/itl/test/test_interval_map/test_interval_map.cpp (original)
+++ sandbox/itl/libs/itl/test/test_interval_map/test_interval_map.cpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -16,6 +16,7 @@
 #include "../test_value_maker.hpp"
 
 #include <boost/itl/interval_map.hpp>
+#include <boost/itl/split_interval_map.hpp>
 
 using namespace std;
 using namespace boost;

Modified: sandbox/itl/libs/itl/test/test_interval_map/test_interval_map_shared.cpp
==============================================================================
--- sandbox/itl/libs/itl/test/test_interval_map/test_interval_map_shared.cpp (original)
+++ sandbox/itl/libs/itl/test/test_interval_map/test_interval_map_shared.cpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -50,3 +50,7 @@
 (test_itl_interval_map_base_is_disjoint_4_bicremental_types, T, bicremental_types)
 { interval_map_base_is_disjoint_4_bicremental_types<interval_map, T, int>();}
 
+BOOST_AUTO_TEST_CASE_TEMPLATE
+(test_itl_interval_map_base_laws_plus_4_bicremental_types, T, bicremental_types)
+{ interval_map_base_laws_plus_4_bicremental_types<T, int, interval_map, split_interval_map>();}
+

Modified: sandbox/itl/libs/itl/test/test_interval_map_mixed/test_interval_map_mixed.cpp
==============================================================================
--- sandbox/itl/libs/itl/test/test_interval_map_mixed/test_interval_map_mixed.cpp (original)
+++ sandbox/itl/libs/itl/test/test_interval_map_mixed/test_interval_map_mixed.cpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -1213,3 +1213,4 @@
 
     BOOST_CHECK_EQUAL( split_A, split_B );
 }
+

Modified: sandbox/itl/libs/itl/test/test_interval_map_shared.hpp
==============================================================================
--- sandbox/itl/libs/itl/test/test_interval_map_shared.hpp (original)
+++ sandbox/itl/libs/itl/test/test_interval_map_shared.hpp 2009-01-18 17:54:22 EST (Sun, 18 Jan 2009)
@@ -825,5 +825,106 @@
 }
 
 
+template<class Type>
+void check_neutrality_plus(const Type& a)
+{
+ Type left = a + neutron<Type>::value();
+ Type right = neutron<Type>::value() + a;
+ BOOST_CHECK_EQUAL(left,right);
+ left = a + Type();
+ right = Type() + a;
+ BOOST_CHECK_EQUAL(left,right);
+}
+
+template<class Type, class TypeB>
+void check_commutativity_plus(const Type& a, const TypeB& b)
+{
+ Type left = a + b;
+ Type right = b + a;
+ BOOST_CHECK_EQUAL(left,right);
+}
+
+template<class Type, class TypeB, class TypeC>
+void check_associativity_plus(const Type& a, const TypeB& b, const TypeC& c)
+{
+ Type left = (a + b) + c;
+ Type right = a + (b + c);
+ BOOST_CHECK_EQUAL(left,right);
+}
+
+template <class T, class U,
+ template<class T, class U,
+ class Traits = neutron_absorber,
+ ITL_COMPARE Compare = ITL_COMPARE_INSTANCE(std::less, U),
+ ITL_COMBINE Combine = ITL_COMBINE_INSTANCE(itl::inplace_plus, U),
+ ITL_SECTION Section = ITL_SECTION_INSTANCE(itl::inplace_star, U),
+ template<class,ITL_COMPARE>class Interval = interval,
+ ITL_ALLOC Alloc = std::allocator
+ >class IntervalMap1,
+ template<class T, class U,
+ class Traits = neutron_absorber,
+ ITL_COMPARE Compare = ITL_COMPARE_INSTANCE(std::less, U),
+ ITL_COMBINE Combine = ITL_COMBINE_INSTANCE(itl::inplace_plus, U),
+ ITL_SECTION Section = ITL_SECTION_INSTANCE(itl::inplace_star, U),
+ template<class,ITL_COMPARE>class Interval = interval,
+ ITL_ALLOC Alloc = std::allocator
+ >class IntervalMap2
+ >
+void interval_map_base_laws_plus_4_bicremental_types()
+{
+ typedef IntervalMap1<T,U> IntervalMap1T;
+ typedef IntervalMap2<T,U> IntervalMap2T;
+
+ T v0 = make<T>(0);
+ T v1 = make<T>(1);
+ T v3 = make<T>(3);
+ T v5 = make<T>(5);
+ T v6 = make<T>(6);
+ T v7 = make<T>(7);
+ T v8 = make<T>(8);
+ T v9 = make<T>(9);
+
+ U u1 = make<U>(1);
+ U u2 = make<U>(2);
+
+ interval<T> I0_1D = interval<T>::rightopen(v0,v1);
+ interval<T> I1_3D = interval<T>::rightopen(v1,v3);
+ interval<T> I3_6D = interval<T>::rightopen(v3,v6);
+ interval<T> I5_7D = interval<T>::rightopen(v5,v7);
+ interval<T> I6_8D = interval<T>::rightopen(v6,v8);
+ interval<T> I8_9D = interval<T>::rightopen(v8,v9);
+
+ typename IntervalMap1T::value_type I0_1D_1(I0_1D, u1);
+ typename IntervalMap1T::value_type I1_3D_1(I1_3D, u1);
+ typename IntervalMap1T::value_type I3_6D_1(I3_6D, u1);
+ typename IntervalMap1T::value_type I5_7D_1(I5_7D, u1);
+ typename IntervalMap1T::value_type I6_8D_1(I6_8D, u1);
+ typename IntervalMap1T::value_type I8_9D_1(I8_9D, u1);
+
+ IntervalMap1T map_a, map_b;
+ map_a.add(I3_6D_1).add(I5_7D_1);
+ map_b.add(I1_3D_1).add(I8_9D_1);
+ map_a = map_a;
+ typename IntervalMap1T::value_type val_pair = I8_9D_1;
+
+ IntervalMap2T map2_a, map2_b;
+ map2_a = map_a;
+ map2_a += map_a;
+ IntervalMap2T join_map = map_a + map2_a;
+ //IntervalMap2T splt_map = map_a + map2_a;
+
+ check_commutativity_plus(map_a, map_b);
+ //check_commutativity_plus(map2_a, map_b);
+ check_commutativity_plus(map_a, val_pair);
+ typename IntervalMap1T::mapping_pair_type v5_u2(v5,u2);
+ check_commutativity_plus(map_b, v5_u2);
+
+ check_associativity_plus(map_a, map_b, map_a);
+ check_associativity_plus(map_a, map_b, map_a);
+
+ check_neutrality_plus(map_a);
+}
+
+
 #endif // __test_itl_interval_map_shared_h_JOFA_080920__
 


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