Update of /cvsroot/boost/boost/libs/xpressive/proto/test
In directory 
sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15702/libs/xpressive/proto/test

Modified Files:
        calculator.cpp lambda.cpp toy_spirit.cpp 
Log Message:
redesign eval() and context to avoid premature return type calculation errors

Index: calculator.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/proto/test/calculator.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- calculator.cpp      3 Feb 2007 00:14:33 -0000       1.2
+++ calculator.cpp      26 Mar 2007 06:06:25 -0000      1.3
@@ -6,6 +6,7 @@
 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
 #include <boost/xpressive/proto/proto.hpp>
+#include <boost/xpressive/proto/context.hpp>
 #include <boost/test/unit_test.hpp>
 
 using namespace boost;
@@ -13,7 +14,7 @@
 struct placeholder {};
 proto::terminal<placeholder>::type const _1 = {{}};
 
-struct calculator
+struct calculator : proto::fanout_context<calculator>
 {
     typedef int result_type;
 

Index: lambda.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/proto/test/lambda.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- lambda.cpp  15 Feb 2007 23:06:56 -0000      1.7
+++ lambda.cpp  26 Mar 2007 06:06:25 -0000      1.8
@@ -72,35 +72,27 @@
 // with the addition of special handling for lambda placeholders
 template<typename Tuple>
 struct lambda_context
-  : proto::context<lambda_context<Tuple> >
 {
-    typedef lambda_context<Tuple> this_type;
-
-    template<typename Sig>
-    struct result
-      : proto::context<lambda_context<Tuple> >::template result<Sig>
-    {};
-
-    template<typename This, typename I>
-    struct result<This(proto::tag::terminal, placeholder<I> const &)>
-    {
-        typedef typename fusion::result_of::at<Tuple, I>::type type;
-    };
-
     lambda_context(Tuple const &args)
       : args_(args)
     {}
 
-    using proto::context<lambda_context<Tuple> >::operator();
+    template<typename Expr, typename EnableIf = void>
+    struct eval
+      : proto::default_eval<Expr, lambda_context<Tuple> >
+    {};
 
-    template<typename I>
-    typename fusion::result_of::at<Tuple, I>::type
-    operator()(proto::tag::terminal, placeholder<I> const &)
+    template<typename Expr>
+    struct eval<Expr, typename enable_if<proto::matches<Expr, 
proto::terminal<placeholder<_> > > >::type>
     {
-        return fusion::at<I>(this->args_);
-    }
+        typedef typename proto::result_of::arg<Expr>::type::arity index;
+        typedef typename fusion::result_of::at<Tuple, index>::type result_type;
+        result_type operator()(Expr const &expr, lambda_context<Tuple> &ctx)
+        {
+            return fusion::at<index>(ctx.args_);
+        }
+    };
 
-private:
     Tuple args_;
 };
 
@@ -121,6 +113,7 @@
       , proto::result_of::eval<T, lambda_context<fusion::tuple<> > >
     >::type nullary_type;
 
+    // Define our operator() that evaluates the lambda expression.
     nullary_type operator()() const
     {
         fusion::tuple<> args;
@@ -128,8 +121,6 @@
         return this->eval(ctx);
     }
 
-    // hide base_type::operator() by defining our own which
-    // evaluates the lambda expression.
     template<typename A0>
     typename proto::result_of::eval<T, lambda_context<fusion::tuple<A0 const 
&> > >::type
     operator()(A0 const &a0) const

Index: toy_spirit.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/proto/test/toy_spirit.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- toy_spirit.cpp      3 Feb 2007 00:14:33 -0000       1.4
+++ toy_spirit.cpp      26 Mar 2007 06:06:25 -0000      1.5
@@ -11,6 +11,7 @@
 #include <boost/assert.hpp>
 #include <boost/mpl/assert.hpp>
 #include <boost/xpressive/proto/proto.hpp>
+#include <boost/xpressive/proto/context.hpp>
 #include <boost/test/unit_test.hpp>
 
 namespace boost
@@ -144,6 +145,7 @@
     template<typename FwdIter, typename Skipper = never_p>
     struct spirit_context
       : std::pair<FwdIter, FwdIter>
+      , proto::fanout_context<spirit_context<FwdIter, Skipper> >
     {
         typedef bool result_type;
         typedef FwdIter iterator;


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to