Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50028 - in sandbox/itl: boost/itl libs/itl/example/boost_party libs/itl_xt/test/meta_functors
From: afojgo_at_[hidden]
Date: 2008-11-29 16:38:13


Author: jofaber
Date: 2008-11-29 16:38:12 EST (Sat, 29 Nov 2008)
New Revision: 50028
URL: http://svn.boost.org/trac/boost/changeset/50028

Log:
Refactored: Deactivated functor equipped map-add and subtract functions.
Aggregate functors are now passed by template parameter only to prevent inconsistent container states.
Added inverse meta function to be able to choose an inverse for a parameter functor.
Stable {msvc-9.0}
Text files modified:
   sandbox/itl/boost/itl/functors.hpp | 45 ++++++++++++++----------
   sandbox/itl/boost/itl/interval.hpp | 32 ++++++++--------
   sandbox/itl/boost/itl/interval_base_map.hpp | 74 ++++++++++++++++++++-------------------
   sandbox/itl/boost/itl/map.hpp | 6 +-
   sandbox/itl/boost/itl/separate_interval_set.hpp | 6 +-
   sandbox/itl/libs/itl/example/boost_party/boost_party.cpp | 14 +++---
   sandbox/itl/libs/itl_xt/test/meta_functors/meta_functors.cpp | 17 ++++++++
   7 files changed, 109 insertions(+), 85 deletions(-)

Modified: sandbox/itl/boost/itl/functors.hpp
==============================================================================
--- sandbox/itl/boost/itl/functors.hpp (original)
+++ sandbox/itl/boost/itl/functors.hpp 2008-11-29 16:38:12 EST (Sat, 29 Nov 2008)
@@ -67,9 +67,6 @@
 
         void operator()(Type& object, const Type& operand)const
         { object += operand; }
-
- static void complement(Type& object, const Type& operand)
- { object -= operand; }
     };
 
     template<>
@@ -82,9 +79,6 @@
         typedef Type type;
         void operator()(Type& object, const Type& operand)const
         { object -= operand; }
-
- static void complement(Type& object, const Type& operand)
- { object += operand; }
     };
 
     template<>
@@ -124,6 +118,17 @@
     inline std::string unary_template_to_string<inplace_star>::apply() { return "*="; }
 
     // ------------------------------------------------------------------------
+ template <typename Type> struct inplace_div
+ : public std::binary_function<Type&, const Type&, void>
+ {
+ void operator()(Type& object, const Type& operand)const
+ { object /= operand; }
+ };
+
+ template<>
+ inline std::string unary_template_to_string<inplace_div>::apply() { return "/="; }
+
+ // ------------------------------------------------------------------------
     template <typename Type> struct inplace_max
         : public std::binary_function<Type&, const Type&, void>
     {
@@ -151,19 +156,21 @@
     template<>
     inline std::string unary_template_to_string<inplace_min>::apply() { return "min="; }
 
-
- // -------------------------------------------------------------------------
- template<template<class>class InplaceBinaryOp, class Type> struct complement
- : public std::binary_function
- < typename InplaceBinaryOp<Type>::type& ,
- const typename InplaceBinaryOp<Type>::type& , void>
- {
- void operator()(typename InplaceBinaryOp<Type>::type& object,
- const typename InplaceBinaryOp<Type>::type& operand)
- {
- return InplaceBinaryOp<Type>::complement(object, operand);
- }
- };
+ //--------------------------------------------------------------------------
+ // Inverse functor
+ template<template<class>class Functor, class Type> struct inverse;
+
+ template<class Type>
+ struct inverse<itl::inplace_plus, Type>
+ {
+ typedef itl::inplace_minus<Type> type;
+ };
+
+ template<class Type>
+ struct inverse<itl::inplace_star, Type>
+ {
+ typedef itl::inplace_div<Type> type;
+ };
 
 }} // namespace itl boost
 

Modified: sandbox/itl/boost/itl/interval.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval.hpp (original)
+++ sandbox/itl/boost/itl/interval.hpp 2008-11-29 16:38:12 EST (Sat, 29 Nov 2008)
@@ -309,11 +309,11 @@
 */
 //@{
     /// Domain type or element type
- typedef DataT data_type;
+ typedef DataT domain_type;
         /// Compare order on the data
     typedef Compare<DataT> domain_compare;
 
- /// The difference type of an interval which is sometimes different form the data_type
+ /// The difference type of an interval which is sometimes different form the domain_type
     typedef typename itl::difference<DataT>::type difference_type;
 
     /// The size type of an interval which is mostly std::size_t
@@ -575,15 +575,15 @@
     bool upper_equal(const interval& x2)const;
 
 public:
- typedef typename boost::call_traits<DataT>::param_type DataP;
+ typedef typename boost::call_traits<DataT>::param_type DomainP;
 
- inline static bool data_less(DataP left, DataP right)
- {return domain_compare()(left, right) ;}
+ inline static bool data_less(DomainP left, DomainP right)
+ {return domain_compare()(left, right) ;}
 
- inline static bool data_less_equal(DataP left, DataP right)
+ inline static bool data_less_equal(DomainP left, DomainP right)
         {return !domain_compare()(right, left );}
 
- inline static bool data_equal(DataP left, DataP right)
+ inline static bool data_equal(DomainP left, DomainP right)
         {return !domain_compare()(left, right) && !domain_compare()(right, left);}
 
 private:
@@ -632,24 +632,24 @@
 template<class IntervalT>
 struct continuous_type
 {
- typedef typename IntervalT::data_type data_type;
- typedef typename boost::call_traits<data_type>::param_type DataP;
+ typedef typename IntervalT::domain_type domain_type;
+ typedef typename boost::call_traits<domain_type>::param_type DomainP;
 
- static bool open_bound_less_equal(DataP x, DataP y)
+ static bool open_bound_less_equal(DomainP x, DomainP y)
         { return IntervalT::data_less_equal(x,y); } //{ return x <= y; }
- static bool open_bound_less (DataP x, DataP y)
+ static bool open_bound_less (DomainP x, DomainP y)
         { return IntervalT::data_less(x,y); } //{ return x < y; }
 };
 
 template<class IntervalT>
 struct discrete_type
 {
- typedef typename IntervalT::data_type data_type;
- typedef typename boost::call_traits<data_type>::param_type DataP;
+ typedef typename IntervalT::domain_type domain_type;
+ typedef typename boost::call_traits<domain_type>::param_type DomainP;
 
- static bool open_bound_less_equal(DataP x, DataP y)
+ static bool open_bound_less_equal(DomainP x, DomainP y)
         { return IntervalT::data_less_equal(x, succ(y)); } //{ return x <= succ(y); }
- static bool open_bound_less (DataP x, DataP y)
+ static bool open_bound_less (DomainP x, DomainP y)
         { return IntervalT::data_less(succ(x),y); } //{ return succ(x) < y ; }
 };
 
@@ -696,7 +696,7 @@
 template<class IntervalT>
 struct discrete_interval
 {
- typedef typename IntervalT::data_type data_type;
+ typedef typename IntervalT::domain_type domain_type;
 
     static typename IntervalT::size_type
         cardinality(const IntervalT& x)

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 2008-11-29 16:38:12 EST (Sat, 29 Nov 2008)
@@ -388,12 +388,12 @@
         If Combinator implements addition (+=) associated values will contain sums.
         If Combinator implements max, associated values will contain maximal values and so on.
     */
- template<class Combiner>
- SubType& add(const base_pair_type& x, const Combiner& combine)
- {
- access::add(*that(), value_type(interval_type(x.KEY_VALUE), x.CONT_VALUE), combine);
- return *that();
- }
+ //template<class Combiner>
+ //CL? SubType& add(const base_pair_type& x, const Combiner& combine)
+ //{
+ // access::add(*that(), value_type(interval_type(x.KEY_VALUE), x.CONT_VALUE), combine);
+ // return *that();
+ //}
 
     /// Addition of a value pair using a Combinator operation.
     /** Addition of a value pair <tt>x := pair(I,y)</tt> where <tt>base_value_type:=pair<DomainT,CodomainT></tt>
@@ -415,18 +415,19 @@
     //SubType& add(const value_type& x, const Combiner& combine)
     //{ that()->add_(x, combine); return *that(); };
 
+private:
     template<class Combiner>
         SubType& add(const value_type& x, const Combiner& combine)
         { access::add(*that(), x, combine); return *that(); }
 
-
- template<class Combiner>
- SubType& add(const value_type& x)
- { access::add(*that(), x, mpl::apply<Combiner,CodomainT>::type()); return *that(); };
-
- template<ITL_COMBINE Combiner>
- SubType& add(const value_type& x)
- { access::add(*that(), x, Combiner<CodomainT>()); return *that(); };
+public:
+ //template<class Combiner>
+ //CL? SubType& add(const value_type& x)
+ //{ access::add(*that(), x, mpl::apply<Combiner,CodomainT>::type()); return *that(); };
+
+ //template<ITL_COMBINE Combiner>
+ //CL? SubType& add(const value_type& x)
+ //{ access::add(*that(), x, Combiner<CodomainT>()); return *that(); };
 
     /// Addition of a base value pair.
     /** Addition of a base value pair <tt>x := pair(k,y)</tt> where <tt>base_value_type:=pair<DomainT,CodomainT></tt>
@@ -477,12 +478,12 @@
         A Combinator for subtract is usually an inverse function of
         the corresponding add<Combinator>.
     */
- template<class Combiner>
- SubType& subtract(const base_pair_type& x, const Combiner& combine)
- {
- that()->subtract_(value_type(interval_type(x.KEY_VALUE), x.CONT_VALUE), combine);
- return *that();
- }
+ //template<class Combiner>
+ //CL? SubType& subtract(const base_pair_type& x, const Combiner& combine)
+ //{
+ // that()->subtract_(value_type(interval_type(x.KEY_VALUE), x.CONT_VALUE), combine);
+ // return *that();
+ //}
 
     /// Subtraction of an interval value pair using a Combinator operation
     /** Subtraction of an interval value pair <tt>x=(I,y)</tt>
@@ -494,11 +495,12 @@
         are decremented by <tt>y</tt>. This is done via the Combinator function
         that is passed a template parameter.
     */
+private:
     template<class Combiner>
     void subtract(const value_type& x, const Combiner& combine)
- { that()->template subtract_(x, combine); }
-
+ { that()->template subtract_(x, combine); }
 
+public:
     /// Subtraction of a base value pair.
     /** Subtraction of a base value pair <tt>x=(k,y)</tt> where <tt>base_value_type:=pair<DomainT,CodomainT></tt>
 
@@ -535,9 +537,9 @@
     SubType& subtract(const value_type& x)
     {
         if(Traits::emits_neutrons)
- access::add(*that(), x, inplace_minus<CodomainT>());
+ access::add(*that(), x, inverse<Combine,CodomainT>::type());
         else
- access::subtract(*that(), x, inplace_minus<CodomainT>());
+ access::subtract(*that(), x, inverse<Combine,CodomainT>::type());
     
         return *that();
     }
@@ -1323,17 +1325,17 @@
     ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_ALLOC Alloc
>
 interval_base_map<SubType,DomainT,CodomainT,
- Traits,Interval,Compare,Alloc>&
+ Traits,Interval,Compare,Combine,Alloc>&
 min_assign
 (
           interval_base_map<SubType,DomainT,CodomainT,
- Traits,Interval,Compare,Alloc>& object,
+ Traits,Interval,Compare,Combine,Alloc>& object,
     const interval_base_map<SubType,DomainT,CodomainT,
- Traits,Interval,Compare,Alloc>& operand
+ Traits,Interval,Compare,Combine,Alloc>& operand
 )
 {
- typedef interval_base_map<SubType,DomainT,CodomainT,Traits,
- Interval,Compare,Alloc> map_type;
+ typedef interval_base_map<SubType,DomainT,CodomainT,
+ Traits,Interval,Compare,Combine,Alloc> map_type;
     const_FORALL(typename map_type, elem_, operand)
         object.template add<inplace_min >(*elem_);
 
@@ -1348,17 +1350,17 @@
     ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_ALLOC Alloc
>
 interval_base_map<SubType,DomainT,CodomainT,
- Traits,Interval,Compare,Alloc>&
+ Traits,Interval,Compare,Combine,Alloc>&
 max_assign
 (
           interval_base_map<SubType,DomainT,CodomainT,
- Traits,Interval,Compare,Alloc>& object,
+ Traits,Interval,Compare,Combine,Alloc>& object,
     const interval_base_map<SubType,DomainT,CodomainT,
- Traits,Interval,Compare,Alloc>& operand
+ Traits,Interval,Compare,Combine,Alloc>& operand
 )
 {
- typedef interval_base_map<SubType,DomainT,CodomainT,Traits,
- Interval,Compare,Alloc> map_type;
+ typedef interval_base_map<SubType,DomainT,CodomainT,
+ Traits,Interval,Compare,Combine,Alloc> map_type;
     const_FORALL(typename map_type, elem_, operand)
         object.template add<inplace_max>(*elem_);
 
@@ -1376,8 +1378,8 @@
    const interval_base_map<SubType,DomainT,CodomainT,Traits,
                            Interval,Compare,Combine,Alloc>& object)
 {
- typedef interval_base_map<SubType,DomainT,CodomainT,Traits,
- Interval,Compare,Alloc> IntervalMapT;
+ typedef interval_base_map<SubType,DomainT,CodomainT,
+ Traits,Interval,Compare,Combine,Alloc> IntervalMapT;
     stream << "{";
     const_FORALL(typename IntervalMapT, it, object)
         stream << "(" << (*it).KEY_VALUE << "->" << (*it).CONT_VALUE << ")";

Modified: sandbox/itl/boost/itl/map.hpp
==============================================================================
--- sandbox/itl/boost/itl/map.hpp (original)
+++ sandbox/itl/boost/itl/map.hpp 2008-11-29 16:38:12 EST (Sat, 29 Nov 2008)
@@ -113,12 +113,12 @@
     public:
         typedef Alloc<typename std::pair<const KeyT, DataT> > allocator_type;
 
- typedef typename itl::map<KeyT, DataT, Traits, Compare, Alloc> type;
- typedef typename std::map<KeyT, DataT, Compare<KeyT>,
+ typedef typename itl::map<KeyT,DataT,Traits, Compare,Combine,Alloc> type;
+ typedef typename std::map<KeyT, DataT, Compare<KeyT>,
                                   allocator_type> base_type;
         typedef typename itl::set<KeyT, Compare, Alloc > set_type;
 
- typedef itl::map<KeyT, DataT, itl::neutron_absorber, Compare, Alloc>
+ typedef itl::map<KeyT,DataT,itl::neutron_absorber,Compare,Combine,Alloc>
                                                                neutron_absorber_type;
 
         typedef Traits traits;

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 2008-11-29 16:38:12 EST (Sat, 29 Nov 2008)
@@ -66,10 +66,10 @@
 */
 template
 <
- typename DomainT,
+ typename DomainT,
     template<class,ITL_COMPARE>class Interval = itl::interval,
- ITL_COMPARE Compare = std::less,
- ITL_ALLOC Alloc = std::allocator
+ ITL_COMPARE Compare = std::less,
+ ITL_ALLOC Alloc = std::allocator
>
 class separate_interval_set:
     public interval_base_set<separate_interval_set<DomainT,Interval,Compare,Alloc>,

Modified: sandbox/itl/libs/itl/example/boost_party/boost_party.cpp
==============================================================================
--- sandbox/itl/libs/itl/example/boost_party/boost_party.cpp (original)
+++ sandbox/itl/libs/itl/example/boost_party/boost_party.cpp 2008-11-29 16:38:12 EST (Sat, 29 Nov 2008)
@@ -68,7 +68,7 @@
 typedef interval_map<ptime, GuestSetT> BoostPartyAttendenceHistoryT;
 
 // A party's height shall be defined as the maximum height of all guests ;-)
-typedef interval_map<ptime, int> BoostPartyHeightHistoryT;
+typedef interval_map<ptime, int, neutron_absorber, interval, less, inplace_max> BoostPartyHeightHistoryT;
 
 void boost_party()
 {
@@ -115,8 +115,8 @@
         interval<ptime>::rightopen(
           time_from_string("2008-05-20 19:30"),
           time_from_string("2008-05-20 23:00")),
- 180),
- inplace_max<int>()
+ 180)
+ //, inplace_max<int>()
         );
 
     tallest_guest.add(
@@ -124,8 +124,8 @@
         interval<ptime>::rightopen(
           time_from_string("2008-05-20 20:10"),
           time_from_string("2008-05-21 00:00")),
- 170),
- inplace_max<int>()
+ 170)
+ //, inplace_max<int>()
         );
 
     tallest_guest.add(
@@ -133,8 +133,8 @@
         interval<ptime>::rightopen(
           time_from_string("2008-05-20 22:15"),
           time_from_string("2008-05-21 00:30")),
- 200),
- inplace_max<int>()
+ 200)
+ //, inplace_max<int>()
         );
 
 

Modified: sandbox/itl/libs/itl_xt/test/meta_functors/meta_functors.cpp
==============================================================================
--- sandbox/itl/libs/itl_xt/test/meta_functors/meta_functors.cpp (original)
+++ sandbox/itl/libs/itl_xt/test/meta_functors/meta_functors.cpp 2008-11-29 16:38:12 EST (Sat, 29 Nov 2008)
@@ -28,6 +28,7 @@
 
 #include <iostream>
 #include <set>
+#include <boost/itl/functors.hpp>
 #include <boost/mpl/apply.hpp>
 #include <boost/mpl/placeholders.hpp>
 
@@ -41,7 +42,7 @@
 
 template<class T, template<class>class U>
 struct unator1{
- void speak(){U<T> obj; obj.speak();}
+ void speak(){U<T> obj; obj.speak();}
 };
 
 template<class T, class U>
@@ -98,6 +99,14 @@
 
 typedef PairSet1<int, std::less<_> > PairSet1_int;
 
+template<template<class>class Functor, class Type> struct inverse;
+
+template<class Type>
+struct inverse<itl::inplace_plus, Type>
+{
+ typedef itl::inplace_minus<Type> type;
+};
+
 int main()
 {
     cout << ">> Interval Template Library: Test meta_functors <<\n";
@@ -110,6 +119,12 @@
 
         PairSet1_int ps1;
 
+ int x = 0, y = 0;
+ itl::inplace_plus<int>()(x,2);
+ inverse<itl::inplace_plus,int>::type()(y,2);
+ cout << "x=" << x << endl;
+ cout << "y=" << y << endl;
+
     return 0;
 }
 


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