$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r71693 - trunk/libs/phoenix/example
From: thom.heller_at_[hidden]
Date: 2011-05-03 06:02:41
Author: theller
Date: 2011-05-03 06:02:39 EDT (Tue, 03 May 2011)
New Revision: 71693
URL: http://svn.boost.org/trac/boost/changeset/71693
Log:
[phoenix]
    - Added identity transform example
    - cleaned up parallel for example
Added:
   trunk/libs/phoenix/example/identity_transform.cpp   (contents, props changed)
Text files modified: 
   trunk/libs/phoenix/example/parallel_for.cpp |    19 ++++++++-----------                     
   1 files changed, 8 insertions(+), 11 deletions(-)
Added: trunk/libs/phoenix/example/identity_transform.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/phoenix/example/identity_transform.cpp	2011-05-03 06:02:39 EDT (Tue, 03 May 2011)
@@ -0,0 +1,118 @@
+
+#include <boost/phoenix.hpp>
+
+#include <iostream>
+#include <sstream>
+
+namespace proto = boost::proto;
+namespace phoenix = boost::phoenix;
+
+template <typename Rule>
+struct identity_transform;
+
+struct identity_actions
+{
+    template <typename Rule>
+    struct when : phoenix::call<identity_transform<Rule> > {};
+};
+
+template <>
+struct identity_actions::when<phoenix::rule::argument>
+    : proto::call<
+        identity_transform<phoenix::rule::argument>(proto::_value, phoenix::_context)
+    > {};
+
+template <>
+struct identity_actions::when<phoenix::rule::terminal>
+    : proto::call<
+        identity_transform<phoenix::rule::terminal>(proto::_value, phoenix::_context)
+    > {};
+
+template <>
+struct identity_actions::when<phoenix::rule::custom_terminal>
+    : proto::lazy<
+        identity_transform<proto::_value>(proto::_value, phoenix::_context)
+    > {};
+
+template <>
+struct identity_transform<phoenix::rule::terminal>
+{
+    typedef std::string result_type;
+
+    template <typename Terminal, typename Context>
+    std::string operator()(Terminal const & terminal, Context) const
+    {
+        std::stringstream ss;
+        ss << "val(" << terminal << ")";
+        return ss.str();
+    }
+
+    template <typename Context>
+    std::string operator()(char const * terminal, Context) const
+    {
+        std::stringstream ss;
+        ss << "val(\"" << terminal << "\")";
+        return ss.str();
+    }
+};
+
+template <typename T>
+struct identity_transform<boost::reference_wrapper<T> >
+{
+    typedef std::string result_type;
+
+    template <typename Terminal, typename Context>
+    std::string operator()(Terminal const & terminal, Context) const
+    {
+        std::stringstream ss;
+        ss << "ref(" << terminal << ")";
+        return ss.str();
+    }
+
+
+    template <int N, typename Context>
+    std::string operator()(boost::reference_wrapper<char const *> terminal, Context) const
+    {
+        std::stringstream ss;
+        ss << "ref(\"" << terminal << "\")";
+        return ss.str();
+    }
+    
+    template <int N, typename Context>
+    std::string operator()(boost::reference_wrapper<char const [N]> terminal, Context) const
+    {
+        std::stringstream ss;
+        ss << "ref(\"" << terminal << "\")";
+        return ss.str();
+    }
+};
+
+template <>
+struct identity_transform<phoenix::rule::argument>
+{
+    typedef std::string result_type;
+
+    template <typename N, typename Context>
+    std::string operator()(N, Context) const
+    {
+        std::stringstream ss;
+        ss << "_" << N::value;
+        return ss.str();
+    }
+};
+
+
+template <typename Expr>
+void identity(Expr const & expr)
+{
+    std::cout << phoenix::eval(expr, phoenix::context(int(), identity_actions())) << "\n";
+}
+
+int main()
+{
+
+    identity(phoenix::val(8));
+    identity(phoenix::val("8"));
+    identity(phoenix::ref("blubb"));
+    identity(phoenix::arg_names::_1);
+}
Modified: trunk/libs/phoenix/example/parallel_for.cpp
==============================================================================
--- trunk/libs/phoenix/example/parallel_for.cpp	(original)
+++ trunk/libs/phoenix/example/parallel_for.cpp	2011-05-03 06:02:39 EDT (Tue, 03 May 2011)
@@ -1,8 +1,6 @@
 
 #include <boost/phoenix.hpp>
 
-#include <iostream>
-
 struct omp_for_eval
 {
     typedef void result_type;
@@ -33,7 +31,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 // Define new custom expression
 BOOST_PHOENIX_DEFINE_EXPRESSION(
-    (client)(omp_for)
+    (omp_for)
   , (boost::phoenix::meta_grammar) // Cond
     (boost::phoenix::meta_grammar) // Init
     (boost::phoenix::meta_grammar) // Step
@@ -43,7 +41,7 @@
 namespace boost { namespace phoenix
 {
     template <>
-    struct default_actions::when<client::rule::omp_for>
+    struct default_actions::when< ::rule::omp_for>
         : boost::phoenix::call< ::omp_for_eval>
     {};
 }}
@@ -55,11 +53,11 @@
         : init(init), cond(cond), step(step) {}
     
     template <typename Do>
-    typename client::expression::omp_for<Init, Cond, Step, Do>::type const
+    typename expression::omp_for<Init, Cond, Step, Do>::type const
     operator[](Do const& do_) const
     {
         return
-            client::expression::
+            expression::
                 omp_for<Init, Cond, Step, Do>::
                     make(init, cond, step, do_);
     }
@@ -115,14 +113,14 @@
 
 // changing evaluation mechanism on the fly
 BOOST_PHOENIX_DEFINE_EXPRESSION(
-    (detail)(parallel)
+    (parallel)
   , (boost::phoenix::meta_grammar)
 )
 
 namespace boost { namespace phoenix
 {
     template <>
-    struct default_actions::when< ::detail::rule::parallel>
+    struct default_actions::when< ::rule::parallel>
         : proto::call<
             evaluator(
                 proto::_child0
@@ -137,12 +135,11 @@
 }}
 
 template <typename Expr>
-typename detail::expression::parallel<Expr>::type const
+typename expression::parallel<Expr>::type const
 parallel(Expr const & expr)
 {
-    return detail::expression::parallel<Expr>::make(expr);
+    return expression::parallel<Expr>::make(expr);
 }
-
 ////////////////////////////////////////////////////////////////////////////////