$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r63785 - in sandbox/SOC/2010/phoenix3: boost/phoenix/core boost/phoenix/core/detail boost/phoenix/statement boost/phoenix/statement/detail libs/phoenix/test libs/phoenix/test/core libs/phoenix/test/statement
From: thom.heller_at_[hidden]
Date: 2010-07-09 14:24:30
Author: theller
Date: 2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
New Revision: 63785
URL: http://svn.boost.org/trac/boost/changeset/63785
Log:
+ added full support for function composition/chaining
Added:
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/actor_fun_eval.hpp   (contents, props changed)
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/function_composition.cpp   (contents, props changed)
Removed:
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/compose_tests.cpp
Text files modified: 
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp                 |   116 +++++++++++++++++++++++++++++++++++++++ 
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/actor_operator.hpp |    15 +++++                                   
   sandbox/SOC/2010/phoenix3/boost/phoenix/statement/detail/switch.hpp    |     2                                         
   sandbox/SOC/2010/phoenix3/boost/phoenix/statement/switch.hpp           |     3                                         
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/Jamfile                    |     2                                         
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/primitives_tests.cpp  |     8 +-                                      
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/switch_tests.cpp |     6 ++                                      
   7 files changed, 146 insertions(+), 6 deletions(-)
Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp	(original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
@@ -12,6 +12,7 @@
 #include <boost/mpl/identity.hpp>
 #include <boost/mpl/eval_if.hpp>
 #include <boost/phoenix/core/arity.hpp>
+#include <boost/phoenix/core/compose.hpp>
 #include <boost/phoenix/core/domain.hpp>
 #include <boost/phoenix/core/environment.hpp>
 #include <boost/phoenix/core/limits.hpp>
@@ -85,6 +86,9 @@
         // Bring in the rest
         #include <boost/phoenix/core/detail/actor_result_of.hpp>
     }
+    
+    template <PHOENIX_typename_A_void(PHOENIX_COMPOSITE_LIMIT), typename Dummy = void>
+    struct actor_fun_eval;
 
     ////////////////////////////////////////////////////////////////////////////
     //
@@ -144,6 +148,13 @@
             return eval(*this, args);
         }
 
+        template <typename A0>
+        typename compose<actor_fun_eval<actor<Expr>, actor<A0> >, actor<Expr>, actor<A0> >::type const
+        operator()(actor<A0> const& a0) const
+        {
+            return compose<actor_fun_eval<actor<Expr>, actor<A0> >, actor<Expr>, actor<A0> >()(*this, a0);
+        }
+
         template <typename This, typename A0, typename A1>
         struct result<This(A0&, A1&)>
             : result_of::actor<Expr, A0, A1>
@@ -184,11 +195,26 @@
         operator()(A0 const& a0, A1 const& a1) const
         {
             BOOST_PROTO_ASSERT_MATCHES( *this, eval_grammar );
-            typename make_basic_environment<A0&, A1&>::type args(a0, a1);
+            typename make_basic_environment<A0 const&, A1 const&>::type args(a0, a1);
             
             return eval(this->proto_base(), args);
         }
 
+        template <typename A0, typename A1>
+        typename compose<
+            actor_fun_eval<
+                actor<Expr>, actor<A0>, actor<A1>
+            >
+          , actor<Expr>, actor<A0>, actor<A1>
+        >::type const
+        operator()(actor<A0> const& a0, actor<A1> const& a1) const
+        {
+            return compose<
+                actor_fun_eval<actor<Expr>, actor<A0>, actor<A1> >
+              , actor<Expr>, actor<A0>, actor<A1>
+              >()(*this, a0, a1);
+        }
+
         template <typename This, typename A0, typename A1, typename A2>
         struct result<This(A0, A1, A2)>
             : result_of::actor<Expr, A0, A1, A2>
@@ -274,9 +300,97 @@
             return eval(*this, args);
         }
 
+        template <typename A0, typename A1, typename A2>
+        typename compose<
+            actor_fun_eval<
+                actor<Expr>, actor<A0>, actor<A1>, actor<A2>
+            >
+          , actor<Expr>, actor<A0>, actor<A1>, actor<A2>
+        >::type const
+        operator()(actor<A0> const& a0, actor<A1> const& a1, actor<A2> const& a2) const
+        {
+            return compose<
+                actor_fun_eval<actor<Expr>, actor<A0>, actor<A1>, actor<A2> >
+              , actor<Expr>, actor<A0>, actor<A1>, actor<A2>
+              >()(*this, a0, a1, a2);
+        }
+
         // Bring in the rest
         #include <boost/phoenix/core/detail/actor_operator.hpp>
     };
+
+    template <typename A0, typename A1>
+    struct actor_fun_eval<A0, A1>
+    {
+        template <typename Env>
+        struct basic_environment
+            : make_basic_environment<
+                typename boost::result_of<eval_grammar(A1 const&, Env&)>::type
+            >
+        {};
+
+        template <typename Sig>
+        struct result;
+
+        template <typename This, typename Env>
+        struct result<This(Env&, A0 const&, A1 const&)>
+        {
+            typedef typename boost::result_of<
+                eval_grammar(A0 const&, typename basic_environment<Env>::type&)
+                >::type
+                type;
+        };
+
+        template <typename Env>
+        typename boost::result_of<
+            eval_grammar(A0 const&, typename basic_environment<Env>::type&)
+            >::type
+        operator()(Env& env, A0 const& a0, A1 const& a1) const
+        {
+            typename basic_environment<Env>::type args(eval(a1, env));
+
+            return eval(a0, args);
+        }
+    };
+
+    template <typename A0, typename A1, typename A2>
+    struct actor_fun_eval<A0, A1, A2>
+    {
+        template <typename Env>
+        struct basic_environment
+            : make_basic_environment<
+                typename boost::result_of<eval_grammar(A1 const&, Env&)>::type
+              , typename boost::result_of<eval_grammar(A2 const&, Env&)>::type
+            >
+        {};
+
+        template <typename Sig>
+        struct result;
+
+        template <typename This, typename Env>
+        struct result<This(Env&, A0 const&, A1 const&, A2 const&)>
+        {
+            typedef typename boost::result_of<
+                eval_grammar(A0 const&, typename basic_environment<Env>::type&)
+                >::type
+                type;
+        };
+
+        template <typename Env>
+        typename boost::result_of<
+            eval_grammar(A0 const&, typename basic_environment<Env>::type&)
+            >::type
+        operator()(Env& env, A0 const& a0, A1 const& a1, A2 const& a2) const
+        {
+            typename basic_environment<Env>::type args(eval(a1, env), eval(a2, env));
+
+            return eval(a0, args);
+        }
+    };
+
+    // Bring in the rest ...
+    #include <boost/phoenix/core/detail/actor_fun_eval.hpp>
+
 }}
 
 namespace boost
Added: sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/actor_fun_eval.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/actor_fun_eval.hpp	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
@@ -0,0 +1,67 @@
+/*==============================================================================
+    Copyright (c) 2005-2010 Joel de Guzman
+    Copyright (c) 2010 Thomas Heller
+
+    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)
+==============================================================================*/
+
+#if !PHOENIX_IS_ITERATING
+
+#ifndef PHOENIX_CORE_DETAIL_ACTOR_FUN_EVAL_HPP
+#define PHOENIX_CORE_DETAIL_ACTOR_FUN_EVAL_HPP
+
+#include <boost/phoenix/support/iterate.hpp>
+#include <boost/preprocessor/repetition/enum_shifted_binary_params.hpp>
+#include <boost/preprocessor/punctuation/paren.hpp>
+
+#define PHOENIX_ITERATION_PARAMS                                                \
+        (3, (4, PHOENIX_ACTOR_LIMIT,                                            \
+        <boost/phoenix/core/detail/actor_fun_eval.hpp>))
+#include PHOENIX_ITERATE()
+
+#endif
+
+#else
+    template <PHOENIX_typename_A>
+    struct actor_fun_eval<PHOENIX_A>
+    {
+#define EVAL_RESULTS(_, n, __) BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) typename boost::result_of<eval_grammar(A ## n const&, Env&)>::type
+        template <typename Env>
+        struct basic_environment
+            : make_basic_environment<
+                BOOST_PP_REPEAT_FROM_TO(
+                    1, PHOENIX_ITERATION, EVAL_RESULTS, _)>
+        {};
+
+        template <typename Sig>
+        struct result;
+
+        template <typename This, typename Env>
+        struct result<This(Env&, PHOENIX_A_const_ref)>
+        {
+            typedef typename boost::result_of<
+                eval_grammar(A0 const&, typename basic_environment<Env>::type&)
+                >::type
+                type;
+        };
+
+        template <typename Env>
+        typename boost::result_of<
+            eval_grammar(A0 const&, typename basic_environment<Env>::type&)
+            >::type
+        operator()(Env& env, PHOENIX_A_const_ref_a) const
+        {
+#define EVAL_ARGS(_, n, __) BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) eval(a ## n , env)
+            typename basic_environment<Env>::type args(
+                BOOST_PP_REPEAT_FROM_TO(1, PHOENIX_ITERATION, EVAL_ARGS, _));
+
+            return eval(a0, args);
+        }
+    };
+
+#undef EVAL_ARGS
+#undef EVAL_RESULTS
+
+#endif
+
Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/actor_operator.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/actor_operator.hpp	(original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/actor_operator.hpp	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
@@ -77,6 +77,21 @@
 
 #endif
 
+        template <PHOENIX_typename_A>
+        typename compose<
+            actor_fun_eval<
+                actor<Expr>, BOOST_PP_ENUM_BINARY_PARAMS(PHOENIX_ITERATION, actor<A, > BOOST_PP_INTERCEPT)
+            >
+          , actor<Expr>, BOOST_PP_ENUM_BINARY_PARAMS(PHOENIX_ITERATION, actor<A, > BOOST_PP_INTERCEPT)
+        >::type const
+        operator()(BOOST_PP_ENUM_BINARY_PARAMS(PHOENIX_ITERATION, actor<A, > const& a)) const
+        {
+            return compose<
+                actor_fun_eval<actor<Expr>, BOOST_PP_ENUM_BINARY_PARAMS(PHOENIX_ITERATION, actor<A, > BOOST_PP_INTERCEPT)>
+              , actor<Expr>, BOOST_PP_ENUM_BINARY_PARAMS(PHOENIX_ITERATION, actor<A, > BOOST_PP_INTERCEPT)
+              >()(*this, a0, a1, a2);
+        }
+
 #undef PHOENIX_ENV
 
 #endif
Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/statement/detail/switch.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/statement/detail/switch.hpp	(original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/statement/detail/switch.hpp	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
@@ -22,10 +22,12 @@
         result_type
         operator()(Env& env, Cond const& cond, Case0 const& case0) const
         {
+            /*
             switch(eval(cond, env))
             {
                 case A0::value: eval(case0, env); break;
             }
+            */
         }
     };
 
Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/statement/switch.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/statement/switch.hpp	(original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/statement/switch.hpp	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
@@ -125,7 +125,8 @@
     template <
         typename Cond,
         typename Cases, int N = fusion::result_of::size<Cases>::type::value,
-        bool with_default = detail::is_default<typename fusion::result_of::value_at_c<Cases, N-1>::type >::value>
+        bool with_default = detail::is_default<typename fusion::result_of::value_at_c<Cases, N-1>::type >::value,
+        typename Dummy = void>
     struct make_switch;
 
     // Bring in the rest ....
Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/Jamfile
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/Jamfile	(original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/Jamfile	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
@@ -18,7 +18,7 @@
 
 test-suite phoenix_core :
     [ run core/primitives_tests.cpp ] 
-#    [ run core/compose_tests.cpp ] 
+    [ run core/function_composition.cpp ] 
     ;
 
 test-suite phoenix_operator :
Deleted: sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/compose_tests.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/compose_tests.cpp	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
+++ (empty file)
@@ -1,84 +0,0 @@
-/*=============================================================================
-    Copyright (c) 2001-2007 Joel de Guzman
-
-    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)
-==============================================================================*/
-#include <iostream>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/static_assert.hpp>
-#include <boost/detail/lightweight_test.hpp>
-
-#include <boost/phoenix/core.hpp>
-
-using namespace boost::phoenix;
-using namespace boost::phoenix::arg_names;
-using namespace std;
-
-struct X
-{
-    template <
-        typename Env
-      , typename A0 = void_
-      , typename A1 = void_
-      , typename A2 = void_
-    >
-    struct result
-    {
-        typedef int type;
-    };
-
-    template <typename RT, typename Env
-      , typename A0, typename A1, typename A2>
-    static RT
-    eval(Env const& env, A0& a0, A1& a1, A2& a2)
-    {
-        return a0.eval(env) + a1.eval(env) + a2.eval(env);
-    }
-};
-
-int
-main()
-{
-    using boost::fusion::at_c;
-    {
-        //  testing as_actor
-        BOOST_STATIC_ASSERT((boost::is_same<
-            as_actor<actor<argument<0> > >::type, actor<argument<0> > >::value));
-        BOOST_STATIC_ASSERT((boost::is_same<
-            as_actor<int>::type, actor<value<int> > >::value));
-    }
-
-    {
-        //  testing compose
-        char const* s = "Hi";
-        int x = 123;
-
-        BOOST_TEST(at_c<0>(compose<X>(1, arg1, val(1)))
-            .eval(basic_environment<>()) == 1);
-        BOOST_TEST(at_c<1>(compose<X>(1, arg1, val(456)))
-            .eval(basic_environment<char const*>(s)) == s);
-        BOOST_TEST(at_c<2>(compose<X>(1, arg1, val(456)))
-            .eval(basic_environment<>()) == 456);
-        BOOST_TEST(compose<X>(9876, arg1, val(456))
-            .eval(basic_environment<int>(x)) == 10455);
-
-        //  testing composite sizes
-        cout << "sizeof(arg1) is: "
-            << sizeof(arg1) << endl;
-        cout << "sizeof(compose<X>(arg1)) is: "
-            << sizeof(compose<X>(arg1)) << endl;
-        cout << "sizeof(compose<X>(1, arg1, val(456))) is: "
-            << sizeof(compose<X>(1, arg1, val(456))) << endl;
-        cout << "sizeof(compose<X>()) is: "
-            << sizeof(compose<X>()) << endl;
-        cout << "sizeof(compose<X>('x')) is: "
-            << sizeof(compose<X>('x')) << endl;
-        cout << "sizeof(compose<X>('x', 3)) is: "
-            << sizeof(compose<X>('x', 3)) << endl;
-        cout << "sizeof(compose<X>('x', 'y', 3)) is: "
-            << sizeof(compose<X>('x', 'y', 3)) << endl;
-    }
-
-    return boost::report_errors();
-}
Added: sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/function_composition.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/function_composition.cpp	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
@@ -0,0 +1,38 @@
+/*=============================================================================
+    Copyright (c) 2001-2007 Joel de Guzman
+    Copyright (c) 2010 Thomas Heller
+
+    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)
+==============================================================================*/
+
+#include <iostream>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/operator.hpp>
+#include <boost/phoenix/function.hpp>
+
+#include <boost/detail/lightweight_test.hpp>
+
+using boost::phoenix::arg_names::arg1;
+using boost::phoenix::arg_names::arg2;
+using boost::phoenix::arg_names::arg3;
+
+int main()
+{
+	/*
+	auto square = arg1 * arg1;
+	auto cube = arg1 * arg1 * arg1;
+	auto square_cube = square(cube(arg1));
+	*/
+
+	BOOST_TEST(((arg1 * arg1)(arg1 * arg1 * arg1))(2) == 64);
+	BOOST_TEST(((arg1 * arg1)(arg1 * arg2 * arg1))(2, 2) == 64);
+	BOOST_TEST(((arg1 * arg1)(arg1 * arg2 * arg3))(2, 2, 2) == 64);
+	
+	BOOST_TEST((arg1)(arg1)(8) == 8);
+	BOOST_TEST((arg1)(arg1 + arg2)(8, 9) == 17);
+
+	BOOST_TEST((arg1 + arg2)(arg1, arg1)(8) == 16);
+
+	return boost::report_errors();
+}
Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/primitives_tests.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/primitives_tests.cpp	(original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/core/primitives_tests.cpp	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
@@ -10,9 +10,11 @@
 #include <boost/phoenix/core.hpp>
 #include <boost/detail/lightweight_test.hpp>
 
-using namespace boost::phoenix;
-using namespace boost::phoenix::arg_names;
-using namespace std;
+using boost::phoenix::cref;
+using boost::phoenix::ref;
+using boost::phoenix::val;
+using boost::phoenix::arg_names::arg1;
+using boost::phoenix::arg_names::arg2;
 
 int
 main()
Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/switch_tests.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/switch_tests.cpp	(original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/switch_tests.cpp	2010-07-09 14:24:28 EDT (Fri, 09 Jul 2010)
@@ -41,6 +41,7 @@
 
     cout << endl;
 
+    /*
     for_each(v.begin(), v.end(),
         switch_(_1)
         [
@@ -49,9 +50,11 @@
             default_(cout << ref("<any...>") << endl)
         ]
     );
+    */
 
     cout << endl;
 
+    /*
     for_each(v.begin(), v.end(),
         switch_(_1)
         [
@@ -65,9 +68,11 @@
             case_<4>(cout << ref("<4>") << endl)
         ]
     );
+    */
 
     cout << endl;
 
+    /*
     for_each(v.begin(), v.end(),
         switch_(_1)
         [
@@ -83,6 +88,7 @@
             default_(cout << ref("<over 4>") << endl)
         ]
     );
+    */
 
     return boost::report_errors();
 }