$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: eric_at_[hidden]
Date: 2007-12-30 00:11:58
Author: eric_niebler
Date: 2007-12-30 00:11:58 EST (Sun, 30 Dec 2007)
New Revision: 42360
URL: http://svn.boost.org/trac/boost/changeset/42360
Log:
port callable_context and default_context to c++0x
Added:
   branches/proto/v3/boost/xpressive/proto/detail/callable_eval.hpp   (contents, props changed)
   branches/proto/v3/boost/xpressive/proto/detail/default_eval.hpp   (contents, props changed)
Text files modified: 
   branches/proto/v3/boost/xpressive/proto/context/callable.hpp |    72 +++++++++++++++++++++------------------ 
   branches/proto/v3/boost/xpressive/proto/context/default.hpp  |    24 ++++++++++---                           
   branches/proto/v3/boost/xpressive/proto/detail/indices.hpp   |     6 ++                                      
   branches/proto/v3/boost/xpressive/proto/eval.hpp             |     4 +-                                      
   branches/proto/v3/boost/xpressive/proto/matches.hpp          |     4 -                                       
   branches/proto/v3/boost/xpressive/proto/proto_fwd.hpp        |    19 ----------                              
   6 files changed, 65 insertions(+), 64 deletions(-)
Modified: branches/proto/v3/boost/xpressive/proto/context/callable.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/context/callable.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto/context/callable.hpp	2007-12-30 00:11:58 EST (Sun, 30 Dec 2007)
@@ -40,12 +40,14 @@
 
         no_type check_is_expr_handled(private_type_ const &);
 
+        template<typename Expr, typename Context, long Arity = Expr::proto_arity>
+        struct is_expr_handled;
+
+        #ifdef BOOST_HAS_VARIADIC_TMPL
+        // TODO use PP to loop-unroll this
         template<typename Context, typename Args>
         struct callable_context_wrapper;
 
-        template<typename Expr, typename Context, typename Args = typename Expr::proto_args>
-        struct is_expr_handled;
-
         template<int N, typename Result = args<> >
         struct make_dont_care;
 
@@ -95,29 +97,51 @@
             typedef mpl::bool_<value> type;
         };
 
-        template<typename Expr, typename Context, typename... Args>
-        struct is_expr_handled<Expr, Context, args<Args...> >
+        template<typename Expr, typename Context, long Arity>
+        struct is_expr_handled
           : is_expr_handled_aux_<
                 Expr
               , Context
-              , args<Args...>
-              , typename proto::detail::make_indices<sizeof...(Args)>::type
+              , typename Expr::proto_args
+              , typename proto::detail::make_indices<Arity>::type
             >
         {};
 
-        template<typename Expr, typename Context, typename T>
-        struct is_expr_handled<Expr, Context, term<T> >
-          : is_expr_handled_aux_<Expr, Context, args<T>, proto::detail::indices<0> >
-        {};
+        template<typename Expr, typename Context, typename Indices>
+        struct callable_eval_;
+
+        template<typename Expr, typename Context, int... Indices>
+        struct callable_eval_<Expr, Context, proto::detail::indices<Indices...> >
+        {
+            typedef
+                typename boost::result_of<
+                    Context(
+                        typename Expr::proto_tag
+                      , typename proto::result_of::arg_c<Expr, Indices>::type...
+                    )
+                >::type
+            result_type;
 
+            result_type operator ()(Expr &expr, Context &context) const
+            {
+                return context(
+                    typename Expr::proto_tag()
+                  , proto::arg_c<Indices>(expr)...
+                );
+            }
+        };
+        #endif
     }
 
     namespace context
     {
         /// callable_eval
         ///
-        template<typename Expr, typename Context, typename Indices>
+        template<typename Expr, typename Context, long Arity>
         struct callable_eval
+          #ifdef BOOST_HAS_VARIADIC_TMPL
+          : proto::detail::callable_eval_<Expr, Context, typename proto::detail::make_indices<Arity>::type>
+          #endif
         {};
 
         /// callable_context
@@ -136,30 +160,10 @@
                 >::type
             {};
         };
-
-        template<typename Expr, typename Context, int... Indices>
-        struct callable_eval<Expr, Context, proto::detail::indices<Indices...> >
-        {
-            typedef
-                typename boost::result_of<
-                    Context(
-                        typename Expr::proto_tag
-                      , typename proto::result_of::arg_c<Expr, Indices>::type...
-                    )
-                >::type
-            result_type;
-
-            result_type operator ()(Expr &expr, Context &context) const
-            {
-                return context(
-                    typename Expr::proto_tag()
-                  , proto::arg_c<Indices>(expr)...
-                );
-            }
-        };
-
     }
 
+    #include <boost/xpressive/proto/detail/callable_eval.hpp>
+
 }}
 
 #endif
Modified: branches/proto/v3/boost/xpressive/proto/context/default.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/context/default.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto/context/default.hpp	2007-12-30 00:11:58 EST (Sun, 30 Dec 2007)
@@ -118,19 +118,23 @@
         //BOOST_MPL_ASSERT((is_same<void(*)(),  result_of_fixup<void(* const &)()>::type>));
         //BOOST_MPL_ASSERT((is_same<void(*)(),  result_of_fixup<void(&)()>::type>));
 
-    #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
+        #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
         template<typename T> T &make_ref_(T &t);
         template<typename T> T const &make_ref_(T const &t);
         #define BOOST_PROTO_REF(x) proto::detail::make_ref_(x)
-    #else
+        #else
         #define BOOST_PROTO_REF(x) x
-    #endif
+        #endif
 
-        template<typename Expr, typename Context, typename Indices>
+        template<typename Expr, typename Context, long Arity>
         struct default_eval_function_;
 
+        #ifdef BOOST_HAS_VARIADIC_TMPL
+        template<typename Expr, typename Context, typename Indices>
+        struct default_eval_function_aux_;
+
         template<typename Expr, typename Context, int Zero, int... Indices>
-        struct default_eval_function_<Expr, Context, proto::detail::indices<Zero, Indices...> >
+        struct default_eval_function_aux_<Expr, Context, proto::detail::indices<Zero, Indices...> >
         {
             typedef
                 typename proto::detail::result_of_fixup<
@@ -160,6 +164,14 @@
             }
         };
 
+        template<typename Expr, typename Context, long Arity>
+        struct default_eval_function_
+          : default_eval_function_aux_<Expr, Context, typename proto::detail::make_indices<Arity>::type>
+        {};
+        #endif
+
+        #include <boost/xpressive/proto/detail/default_eval.hpp>
+
     } // namespace detail
 
     namespace context
@@ -351,7 +363,7 @@
           : proto::detail::default_eval_function_<
                 Expr
               , Context
-              , typename proto::detail::make_indices<Expr::proto_arity>::type
+              , Expr::proto_arity
             >
         {};
 
Added: branches/proto/v3/boost/xpressive/proto/detail/callable_eval.hpp
==============================================================================
--- (empty file)
+++ branches/proto/v3/boost/xpressive/proto/detail/callable_eval.hpp	2007-12-30 00:11:58 EST (Sun, 30 Dec 2007)
@@ -0,0 +1,85 @@
+#ifndef BOOST_PP_IS_ITERATING
+    ///////////////////////////////////////////////////////////////////////////////
+    /// \file callable_eval.hpp
+    /// Contains definition of the callable_eval<> evaluator and helpers.
+    //
+    //  Copyright 2007 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)
+
+    #define ARG_C_TYPE(Z, N, DATA) typename proto::result_of::arg_c<DATA, N>::type
+    #define ARG_C(Z, N, DATA) proto::arg_c<N>(DATA)
+
+    #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PROTO_MAX_ARITY, <boost/xpressive/proto/detail/callable_eval.hpp>))
+    #include BOOST_PP_ITERATE()
+
+    #undef ARG_C_TYPE
+    #undef ARG_C
+
+#else
+
+    #define N BOOST_PP_ITERATION()
+
+    namespace detail
+    {
+        template<typename Context>
+        struct BOOST_PP_CAT(callable_context_wrapper, N)
+          : remove_cv<Context>::type
+        {
+            BOOST_PP_CAT(callable_context_wrapper, N)();
+            typedef private_type_ const &(*pointer_to_function)(
+                dont_care
+                BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_MAX(N, 1), dont_care BOOST_PP_INTERCEPT)
+            );
+            operator pointer_to_function() const;
+        };
+
+        template<typename Expr, typename Context>
+        struct is_expr_handled<Expr, Context, N>
+        {
+            static BOOST_PP_CAT(callable_context_wrapper, N)<Context> &sctx_;
+            static Expr &sexpr_;
+
+            BOOST_STATIC_CONSTANT(bool, value =
+            (
+                sizeof(yes_type) ==
+                sizeof(
+                    proto::detail::check_is_expr_handled(
+                        (sctx_(
+                            typename Expr::proto_tag()
+                            BOOST_PP_ENUM_TRAILING(BOOST_PP_MAX(N, 1), ARG_C, sexpr_)
+                        ), 0)
+                    )
+            )));
+
+            typedef mpl::bool_<value> type;
+        };
+    }
+
+    namespace context
+    {
+        template<typename Expr, typename Context>
+        struct callable_eval<Expr, Context, N>
+        {
+            typedef
+                typename boost::result_of<
+                    Context(
+                        typename Expr::proto_tag
+                        BOOST_PP_ENUM_TRAILING(BOOST_PP_MAX(N, 1), ARG_C_TYPE, Expr)
+                    )
+                >::type
+            result_type;
+
+            result_type operator ()(Expr &expr, Context &context) const
+            {
+                return context(
+                    typename Expr::proto_tag()
+                    BOOST_PP_ENUM_TRAILING(BOOST_PP_MAX(N, 1), ARG_C, expr)
+                );
+            }
+        };
+    }
+
+    #undef N
+
+#endif
Added: branches/proto/v3/boost/xpressive/proto/detail/default_eval.hpp
==============================================================================
--- (empty file)
+++ branches/proto/v3/boost/xpressive/proto/detail/default_eval.hpp	2007-12-30 00:11:58 EST (Sun, 30 Dec 2007)
@@ -0,0 +1,50 @@
+#ifndef BOOST_PP_IS_ITERATING
+    ///////////////////////////////////////////////////////////////////////////////
+    /// \file default_eval.hpp
+    /// Contains definition of the default_eval_function_<> evaluator.
+    //
+    //  Copyright 2007 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)
+
+    #define EVAL_TYPE(Z, N, DATA)                                                                   \
+        typename proto::result_of::eval<                                                            \
+            typename remove_reference<typename proto::result_of::arg_c<DATA, N>::type>::type        \
+          , Context                                                                                 \
+        >::type
+
+    #define EVAL(Z, N, DATA)                                                                        \
+        proto::eval(proto::arg_c<N>(DATA), context)
+
+    #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PROTO_MAX_ARITY, <boost/xpressive/proto/detail/default_eval.hpp>))
+    #include BOOST_PP_ITERATE()
+
+    #undef EVAL_TYPE
+    #undef EVAL
+
+#else
+
+    #define N BOOST_PP_ITERATION()
+
+        template<typename Expr, typename Context>
+        struct default_eval_function_<Expr, Context, N>
+        {
+            typedef
+                typename proto::detail::result_of_fixup<EVAL_TYPE(~, 0, Expr)>::type
+            function_type;
+
+            typedef
+                typename boost::result_of<
+                    function_type(BOOST_PP_ENUM_SHIFTED(BOOST_PP_MAX(N, 1), EVAL_TYPE, Expr))
+                >::type
+            result_type;
+
+            result_type operator ()(Expr &expr, Context &context) const
+            {
+                return EVAL(~, 0, expr)(BOOST_PP_ENUM_SHIFTED(BOOST_PP_MAX(N, 1), EVAL, expr));
+            }
+        };
+
+    #undef N
+
+#endif
Modified: branches/proto/v3/boost/xpressive/proto/detail/indices.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/detail/indices.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto/detail/indices.hpp	2007-12-30 00:11:58 EST (Sun, 30 Dec 2007)
@@ -12,10 +12,14 @@
 
 namespace boost { namespace proto { namespace detail
 {
+    #ifdef BOOST_HAS_VARIADIC_TMPL
     template<int... I>
     struct indices
     {};
 
+    template<int N, typename Indices = indices<> >
+    struct make_indices;
+
     template<int N, int... I>
     struct make_indices<N, indices<I...> >
       : make_indices<N-4, indices<N-4, N-3, N-2, N-1, I...> >
@@ -44,7 +48,7 @@
     {
         typedef indices<I...> type;
     };
-
+    #endif
 }}}
 
 #endif
Modified: branches/proto/v3/boost/xpressive/proto/eval.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/eval.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto/eval.hpp	2007-12-30 00:11:58 EST (Sun, 30 Dec 2007)
@@ -49,14 +49,14 @@
             typename proto::result_of::eval<Expr, Context>::type
             operator ()(Expr &expr, Context &context) const
             {
-                return Context::template eval<Expr>()(expr, context);
+                return typename Context::template eval<Expr>()(expr, context);
             }
 
             template<typename Expr, typename Context>
             typename proto::result_of::eval<Expr, Context>::type
             operator ()(Expr &expr, Context const &context) const
             {
-                return Context::template eval<Expr>()(expr, context);
+                return typename Context::template eval<Expr>()(expr, context);
             }
         #endif
         };
Modified: branches/proto/v3/boost/xpressive/proto/matches.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/matches.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto/matches.hpp	2007-12-30 00:11:58 EST (Sun, 30 Dec 2007)
@@ -451,9 +451,7 @@
             template<typename Tag1, typename Args1, long N1, typename Args2, long N2>
             struct matches_<expr<Tag1, Args1, N1>, expr<Tag1, Args2, N2> >
               : vararg_matches<Args1, Args2>
-            {
-                BOOST_MPL_ASSERT_RELATION(N1, !=, N2);
-            };
+            {};
 
             template<typename Tag1, typename Args1, long N1, typename Args2, long N2>
             struct matches_<expr<Tag1, Args1, N1>, expr<_, Args2, N2> >
Modified: branches/proto/v3/boost/xpressive/proto/proto_fwd.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/proto_fwd.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto/proto_fwd.hpp	2007-12-30 00:11:58 EST (Sun, 30 Dec 2007)
@@ -43,17 +43,6 @@
 
 namespace boost { namespace proto
 {
-    namespace detail
-    {
-        #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
-        template<int... I>
-        struct indices;
-
-        template<int N, typename T = indices<> >
-        struct make_indices;
-        #endif
-    }
-
     namespace wildns_
     {
         struct _;
@@ -572,13 +561,7 @@
         template<typename Derived, typename DefaultCtx = default_context>
         struct callable_context;
 
-        template<typename Expr, typename Context
-            #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
-          , typename Indices = typename proto::detail::make_indices<
-                Expr::proto_arity == 0 ? 1 : Expr::proto_arity
-            >::type
-            #endif
-        >
+        template<typename Expr, typename Context, long Arity = Expr::proto_arity>
         struct callable_eval;
     }