Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66925 - in sandbox/variadic_templates/libs/mpl/sandbox: . de_bruijn
From: cppljevans_at_[hidden]
Date: 2010-11-30 17:05:43


Author: cppljevans
Date: 2010-11-30 17:05:42 EST (Tue, 30 Nov 2010)
New Revision: 66925
URL: http://svn.boost.org/trac/boost/changeset/66925

Log:
test of if_recur
Added:
   sandbox/variadic_templates/libs/mpl/sandbox/if_recur.cpp (contents, props changed)
Text files modified:
   sandbox/variadic_templates/libs/mpl/sandbox/de_bruijn/eval.cpp | 148 +++++++++++++++++++++++++++++++++------
   1 files changed, 123 insertions(+), 25 deletions(-)

Modified: sandbox/variadic_templates/libs/mpl/sandbox/de_bruijn/eval.cpp
==============================================================================
--- sandbox/variadic_templates/libs/mpl/sandbox/de_bruijn/eval.cpp (original)
+++ sandbox/variadic_templates/libs/mpl/sandbox/de_bruijn/eval.cpp 2010-11-30 17:05:42 EST (Tue, 30 Nov 2010)
@@ -37,6 +37,17 @@
  * mentioned above (after //Purpose:) is for *values*.
  */
 {
+
+#define EVAL_MPL_PRINT
+#ifdef EVAL_MPL_PRINT
+ template
+ < typename Term
+ , typename Args
+ >
+struct eval_show
+{};
+#endif
+
   template
   < typename Repl=package<> //Replacements for varb's
   , unsigned DepthAbstraction=0 //which are bound this high up.
@@ -58,10 +69,10 @@
    * Defaults to identity metafunction.
    *
    * Where:
- * Term = lamb<typename Body>
+ * Term = lamb<Term Body>
    * | varb<unsigned ArgIndex,unsigned DepthBinding>
- * | Prim<typename... Args>
- * | appl<typename Fun,typename... Args>
+ * | Prim<Term... Args>
+ * | appl<Term Fun,Term... Args>
    * | //anything else
    */
 {
@@ -160,8 +171,8 @@
 {
 };
   template
- < template<typename...> class Prim //meta function (has typename Prim<Args...>::type ).
- , typename... PArgs//Arguments to Prim.
+ < template<typename...> class Prim
+ , typename... PArgs
   , typename ArgsDepth//instance of args
>
 struct eval
@@ -169,12 +180,21 @@
   , ArgsDepth
>
 {
+ #ifdef EVAL_MPL_PRINT
+ print
+ < eval_show
+ < Prim<PArgs...>
+ , ArgsDepth
+ >
+ >
+ print_eval;
+ #endif
     typedef Prim<typename eval<PArgs,ArgsDepth>::type...> type;
 };
 
   template
- < template<typename...> class Prim
- , typename... PArgs
+ < template<typename...> class Prim //meta function (has typename Prim<Args...>::type ).
+ , typename... PArgs //Arguments to Prim.
   , typename Repl
>
 struct eval
@@ -183,6 +203,15 @@
>
   : Prim<typename eval<PArgs,args<Repl,0> >::type...>
 {
+ #ifdef EVAL_MPL_PRINT
+ print
+ < eval_show
+ < Prim<PArgs...>
+ , args<Repl,0>
+ >
+ >
+ print_eval;
+ #endif
 };
 
   template
@@ -220,8 +249,18 @@
     , args<Args,1>
>
 {
+ #ifdef EVAL_MPL_PRINT
+ print
+ < eval_show
+ < lamb
+ < Body
+ >
+ , args<Args,0>
+ >
+ >
+ print_eval;
+ #endif
 };
-
   template
   < typename Fun
   , typename... Args
@@ -230,9 +269,13 @@
   /**@brief
    * Apply function, Fun to args, Args...
    */
+#if 1
+;
+#else
 {
     typedef appl type;
 };
+#endif
   template
   < typename Fun
   , typename... FArgs
@@ -258,19 +301,59 @@
   , args<ArgsD,0>
>
   : eval
+ #if 0
+ < typename eval<Fun,args<ArgsD,0> >::type
+ #else
     < Fun
+ #endif
     , args
       < package
- #if 1
         < typename eval<FArgs,args<ArgsD,0> >::type...
- #else
+ >
+ , 0
+ >
+ >
+{
+ #ifdef EVAL_MPL_PRINT
+ print
+ < eval_show
+ < appl<Fun,FArgs...>
+ , args<ArgsD,0>
+ >
+ >
+ print_eval
+ ;
+ #endif
+};
+
+ template
+ < typename Fun
+ , typename... FArgs
+ >
+struct eval
+ < appl<Fun,FArgs...>
+ , args<package<>,0>
+ >
+ : eval
+ < Fun
+ , args
+ < package
         < FArgs...
- #endif
>
       , 0
>
>
-{};
+{
+ #ifdef EVAL_MPL_PRINT
+ print
+ < eval_show
+ < appl<Fun,FArgs...>
+ , args<package<>,0>
+ >
+ >
+ print_eval;
+ #endif
+};
 
   template
   < typename Term
@@ -352,7 +435,7 @@
     };
     
 }//exit shorthand namespace
-#if 1
+#if 0
 #include <boost/mpl/next.hpp>
 namespace test_basic
 {
@@ -422,10 +505,10 @@
>
     , 0
>
- >
+ >::type
 appl_v0_v1_next_9
 ;
-#if 1
+#if 0
 print<appl_v0_v1_next_9> print_appl_v0_v1_next_9;
 #else
 BOOST_MPL_ASSERT((equal_to<appl_v0_v1_next_9,int_<10> >));
@@ -640,7 +723,7 @@
 }
 #endif //#if namespace wiki
 
-#if 0
+#if 1
 #include <boost/mpl/plus.hpp>
 #include <boost/mpl/push_front.hpp>
 #include <boost/mpl/front.hpp>
@@ -651,8 +734,7 @@
 namespace fold_composed_op
 {
 /**@brief
- * The is the real problem which prompted creation of
- * the simplified problem in [apply_apply].
+ * Fold with a composed binary op.
  */
    using namespace dbr;
    using namespace shorthand;
@@ -711,6 +793,7 @@
>
     ints
     ;
+ #if 0
         typedef
       fold_pack
       < op0
@@ -725,7 +808,7 @@
        , i<106>::_
>
      ));
-
+ #endif
         typedef
       wrap_lamb<op0>::type
     lamb_op0
@@ -741,11 +824,18 @@
>
     op1
     ;
+ //#define LAMB_OP1
+ #ifdef LAMB_OP1
+ typedef
+ wrap_lamb<op1>::type
+ lamb_op1
+ ;
+ #endif
         typedef
       package<state_now0>
     state_now1
     ;
-
+ #if 0
         typedef
       eval
       < appl
@@ -778,11 +868,15 @@
         , i<10>::_
>
       ));
-
+ #endif
         typedef
       eval
       < appl
+ #ifdef LAMB_OP1
+ < lamb_op1
+ #else
         < op1
+ #endif
         , i<1>::_
         , state_now1
>
@@ -795,11 +889,16 @@
         , package<i<101>::_,i<100>::_>
>
       ));
-
+ #if 0
+ print<op1_state1> print_op1_state1;
         typedef
       eval
       < appl
+ #ifdef LAMB_OP1
+ < lamb_op1
+ #else
         < op1
+ #endif
         , i<2>::_
         , op1_state1
>
@@ -812,10 +911,9 @@
         , package<i<103>::_,i<101>::_,i<100>::_>
>
       ));
-
         typedef
       fold_pack
- < op1
+ < lamb_op1
       , state_now1
       , ints
>::type
@@ -827,6 +925,6 @@
         , package<i<106>::_,i<103>::_,i<101>::_,i<100>::_>
>
       ));
-
+ #endif
 }
 #endif //#if namespace fold_composed_op

Added: sandbox/variadic_templates/libs/mpl/sandbox/if_recur.cpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/libs/mpl/sandbox/if_recur.cpp 2010-11-30 17:05:42 EST (Tue, 30 Nov 2010)
@@ -0,0 +1,265 @@
+
+// Copyright Larry Evans 2009
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/mpl for documentation.
+
+// $Id$
+// $Date: 2009/04/19 14:39:38 $
+// $Revision: 1.35 $
+
+#include <boost/mpl/if_recur.hpp>
+
+#include <boost/mpl/begin_end.hpp>
+#include <boost/mpl/range_c.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/arg.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/push_front.hpp>
+#include <boost/mpl/next.hpp>
+#include <boost/mpl/deref.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/vector_c.hpp>
+#include <boost/mpl/equal.hpp>
+#include <boost/mpl/less.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+#include <boost/mpl/aux_/test.hpp>
+
+using namespace mpl;
+
+ template
+ < class Iter
+ , class Container
+ >
+ struct
+iter_container
+{
+ typedef iter_container type;
+ typedef Iter iter;
+ typedef Container container;
+};
+
+ template
+ < class IterContainer
+ >
+ struct
+down_next
+{
+ typedef
+ iter_container
+ < typename next<typename IterContainer::iter>::type
+ , typename IterContainer::container
+ >
+ type
+ ;
+};
+ template
+ < class IterContainer
+ >
+ struct
+down_next_push
+{
+ typedef typename
+ IterContainer::iter
+ iter
+ ;
+ typedef
+ iter_container
+ < typename next<iter>::type
+ , typename push_front
+ < typename IterContainer::container
+ , typename deref<iter>::type
+ >::type
+ >
+ type
+ ;
+};
+
+ template
+ < class StateNow
+ , class ContainerUp
+ >
+ struct
+up_push
+{
+ typedef
+ typename push_front
+ < ContainerUp
+ , typename deref<typename StateNow::iter>::type
+ >::type
+ type
+ ;
+};
+ template
+ < class StateNow
+ , class IterEnd
+ >
+ struct
+not_end
+/**@brief
+ * not at end iterator?
+ */
+: not_
+ < is_same
+ < typename StateNow::iter
+ , IterEnd
+ >
+ >
+{
+};
+ template
+ < class IterContainer
+ >
+ struct
+else_container
+/**@brief
+ * just return the container, since
+ * on the way up the recursion, the
+ * up_push operation, if present,
+ * will just need the container and
+ * has no need for the iterator.
+ */
+{
+ typedef
+ typename IterContainer::container
+ type
+ ;
+};
+
+ typedef
+ range_c
+ < int
+ , 9
+ , 13
+ >
+numbers
+;
+ typedef
+ begin<numbers>::type
+beg_numb
+;
+ typedef
+ end<numbers>::type
+end_numb
+;
+ typedef
+ iter_container<beg_numb,vector<> >
+beg_vector
+;
+#if 1
+ template
+ < class StateNow
+ , class StateUp
+ >
+ struct if_recur_up_default
+ {
+ typedef
+ StateUp
+ type
+ ;
+ };
+
+ typedef
+ if_recur
+ < identity<beg_vector>
+ , not_end<arg<1>,end_numb>
+ , down_next_push<arg<1> >
+ , if_recur_up_default<arg<1>,arg<2> >
+ , else_container<arg<1> >
+ >::type
+result_down_push
+;
+ typedef
+ vector_c<int,12,11,10,9>
+expected_down_push
+;
+BOOST_MPL_ASSERT((equal<result_down_push,expected_down_push>));
+#endif
+#if 1
+ typedef
+ if_recur
+ < identity<beg_vector>
+ , not_end<arg<1>,end_numb>
+ , down_next_push<arg<1> >
+ , up_push<arg<1>,arg<2> >
+ , else_container<arg<1> >
+ >::type
+result_down_up_push
+;
+ typedef
+ vector_c<int,9,10,11,12,12,11,10,9>
+expected_down_up_push
+;
+BOOST_MPL_ASSERT((equal<result_down_up_push,expected_down_up_push>));
+#endif
+#if 1
+ typedef
+ if_recur
+ < identity<beg_vector>
+ , not_end<arg<1>,end_numb>
+ , down_next<arg<1> >
+ , up_push<arg<1>,arg<2> >
+ , else_container<arg<1> >
+ >::type
+result_up_push
+;
+ typedef
+ vector_c<int,9,10,11,12>
+expected_up_push
+;
+BOOST_MPL_ASSERT((equal<result_up_push,expected_up_push>));
+#endif
+#if 1
+ template
+ < class StateNow
+ , class IterEnd
+ , class LessCriteria
+ >
+ struct
+fwdpred_short_circuit
+: and_
+ < not_end<StateNow,IterEnd>
+ , less
+ < typename deref<typename StateNow::iter>::type
+ , LessCriteria
+ >
+ >
+{
+};
+ typedef
+ begin<expected_down_up_push>::type
+beg_short_circuit
+;
+ typedef
+ end<expected_down_up_push>::type
+end_short_circuit
+;
+ typedef
+ iter_container<beg_short_circuit,vector<> >
+beg_vector_short_circuit
+;
+ typedef
+ if_recur
+ < identity<beg_vector_short_circuit>
+ , fwdpred_short_circuit
+ < arg<1>
+ , end_short_circuit
+ , int_<11>
+ >
+ , down_next<arg<1> >
+ , up_push<arg<1>,arg<2> >
+ , else_container<arg<1> >
+ >::type
+result_short_circuit
+;
+ typedef
+ vector_c<int,9,10>
+expected_short_circuit
+;
+BOOST_MPL_ASSERT((equal<result_short_circuit,expected_short_circuit>));
+#endif


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