Update of /cvsroot/boost/boost/boost/xpressive/proto/transform
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv6762/proto/transform

Modified Files:
        fold.hpp fold_tree.hpp 
Added Files:
        function.hpp 
Log Message:
add functionN transform, add optional State parameter to fold transform

--- NEW FILE: function.hpp ---
///////////////////////////////////////////////////////////////////////////////
/// \file function.hpp
/// Proto transforms for applying a function object.
//
//  Copyright 2004 Eric Niebler. 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)

#ifndef BOOST_PROTO_TRANSFORM_FUNCTION_HPP_EAN_06_23_2007
#define BOOST_PROTO_TRANSFORM_FUNCTION_HPP_EAN_06_23_2007

#include <boost/xpressive/proto/detail/prefix.hpp>
#include <boost/utility/result_of.hpp>
#include <boost/xpressive/proto/proto_fwd.hpp>
#include <boost/xpressive/proto/detail/suffix.hpp>

namespace boost { namespace proto { namespace transform
{

    // Apply a function object, passing just Expr
    template<typename Grammar, typename Function1>
    struct function1
      : Grammar
    {
        function1() {}

        template<typename Expr, typename State, typename Visitor>
        struct apply
          : boost::result_of<
                Function1(
                    typename Grammar::template apply<Expr, State, Visitor>::type
                )
            >
        {};

        template<typename Expr, typename State, typename Visitor>
        static typename apply<Expr, State, Visitor>::type
        call(Expr const &expr, State const &state, Visitor &visitor)
        {
            return Function1()(Grammar::call(expr, state, visitor));
        }
    };

    // Apply a function object, passing Expr and State
    template<typename Grammar, typename Function2>
    struct function2
      : Grammar
    {
        function2() {}

        template<typename Expr, typename State, typename Visitor>
        struct apply
          : boost::result_of<
                Function2(
                    typename Grammar::template apply<Expr, State, Visitor>::type
                  , State const &
                )
            >
        {};

        template<typename Expr, typename State, typename Visitor>
        static typename apply<Expr, State, Visitor>::type
        call(Expr const &expr, State const &state, Visitor &visitor)
        {
            return Function2()(Grammar::call(expr, state, visitor), state);
        }
    };

    // Apply a function object, passing Expr, State and Visitor
    template<typename Grammar, typename Function3>
    struct function3
      : Grammar
    {
        function3() {}

        template<typename Expr, typename State, typename Visitor>
        struct apply
          : boost::result_of<
                Function3(
                    typename Grammar::template apply<Expr, State, Visitor>::type
                  , State const &
                  , Visitor &
                )
            >
        {};

        template<typename Expr, typename State, typename Visitor>
        static typename apply<Expr, State, Visitor>::type
        call(Expr const &expr, State const &state, Visitor &visitor)
        {
            return Function3()(Grammar::call(expr, state, visitor), state, 
visitor);
        }
    };

}}}

#endif

Index: fold.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/proto/transform/fold.hpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- fold.hpp    16 Jun 2007 05:46:16 -0000      1.12
+++ fold.hpp    23 Jun 2007 07:41:20 -0000      1.13
@@ -20,6 +20,7 @@
     #include <boost/preprocessor/repetition/repeat.hpp>
     #include <boost/xpressive/proto/proto_fwd.hpp>
     #include <boost/xpressive/proto/traits.hpp>
+    #include <boost/xpressive/proto/transform/branch.hpp>
     #include <boost/xpressive/proto/detail/suffix.hpp>
 
     namespace boost { namespace proto { namespace transform
@@ -73,8 +74,13 @@
 
         // A fold transform that transforms the left sub-tree and
         // uses the result as state while transforming the right.
-        template<typename Grammar>
+        template<typename Grammar, typename State>
         struct fold
+          : branch<fold<Grammar>, State>
+        {};
+
+        template<typename Grammar>
+        struct fold<Grammar, void>
           : Grammar
         {
             fold() {}
@@ -94,8 +100,13 @@
 
         // A reverse_fold compiler that compiles the right sub-tree and
         // uses the result as state while compiling the left.
-        template<typename Grammar>
+        template<typename Grammar, typename State>
         struct reverse_fold
+          : branch<reverse_fold<Grammar>, State>
+        {};
+
+        template<typename Grammar>
+        struct reverse_fold<Grammar, void>
           : Grammar
         {
             reverse_fold() {}

Index: fold_tree.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/proto/transform/fold_tree.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- fold_tree.hpp       19 Jun 2007 01:07:11 -0000      1.1
+++ fold_tree.hpp       23 Jun 2007 07:41:20 -0000      1.2
@@ -43,7 +43,7 @@
 
     /// fold_tree
     ///
-    template<typename Tag, typename Grammar, typename State = void>
+    template<typename Tag, typename Grammar, typename State>
     struct fold_tree
       : transform::branch<
             transform::fold<
@@ -62,7 +62,7 @@
 
     /// reverse_fold_tree
     ///
-    template<typename Tag, typename Grammar, typename State = void>
+    template<typename Tag, typename Grammar, typename State>
     struct reverse_fold_tree
       : transform::branch<
             transform::reverse_fold<


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to