Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-12-17 16:48:23


Author: eric_niebler
Date: 2007-12-17 16:48:22 EST (Mon, 17 Dec 2007)
New Revision: 42135
URL: http://svn.boost.org/trac/boost/changeset/42135

Log:
port by_value_generator, remove fanout_args
Added:
   branches/proto/v3/boost/xpressive/proto/detail/by_value_generator.hpp (contents, props changed)
Text files modified:
   branches/proto/v3/boost/xpressive/proto/args.hpp | 35 ---------------------
   branches/proto/v3/boost/xpressive/proto/generate.hpp | 66 ++++++---------------------------------
   2 files changed, 10 insertions(+), 91 deletions(-)

Modified: branches/proto/v3/boost/xpressive/proto/args.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/args.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/args.hpp 2007-12-17 16:48:22 EST (Mon, 17 Dec 2007)
@@ -49,41 +49,6 @@
                 typedef void cdr_type;
             };
 
- struct fanout_args_fun
- {
- template<typename Sig>
- struct result;
-
- template<typename This, typename Fun, typename... Args>
- struct result<This(Fun, cons<Args...>)>
- : boost::result_of<UNCVREF(Fun)(UNCVREF(Args)...)>
- {};
-
- template<typename Fun, typename... Args>
- typename boost::result_of<Fun(Args...)>::type
- operator()(Fun const &fun, cons<Args...> const &cons) const
- {
- typedef typename boost::result_of<Fun(Args...)>::type type;
- return this->call_<type>(fun, cons.cdr, cons.car);
- }
-
- private:
-
- template<typename Ret, typename Fun, typename Tail, typename... Head>
- static Ret call_(Fun const &fun, Tail const &cons, Head const &...head)
- {
- return call_<Ret>(fun, cons.cdr, head..., cons.car);
- }
-
- template<typename Ret, typename Fun, typename... Head>
- static Ret call_(Fun const &fun, cons<> const &, Head const &... head)
- {
- return fun(head...);
- }
- };
-
- fanout_args_fun const fanout_args = {};
-
         #define LBRACE(Z, N, DATA) {
         #define RBRACE(Z, N, DATA) }
         #define CDR_TYPE(Z, N, DATA) ::cdr_type

Added: branches/proto/v3/boost/xpressive/proto/detail/by_value_generator.hpp
==============================================================================
--- (empty file)
+++ branches/proto/v3/boost/xpressive/proto/detail/by_value_generator.hpp 2007-12-17 16:48:22 EST (Mon, 17 Dec 2007)
@@ -0,0 +1,105 @@
+#ifndef BOOST_PP_IS_ITERATING
+ ///////////////////////////////////////////////////////////////////////////////
+ /// \file by_value_generator.hpp
+ /// Definintion of the by_value_generator_ helper
+ //
+ // 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)
+
+ #ifndef BOOST_PROTO_DETAIL_BY_VALUE_GENERATOR_HPP_EAN_11_07_2007
+ #define BOOST_PROTO_DETAIL_BY_VALUE_GENERATOR_HPP_EAN_11_07_2007
+
+ #include <boost/xpressive/proto/proto_fwd.hpp>
+ #include <boost/xpressive/proto/detail/cat_args.hpp>
+ #include <boost/xpressive/proto/detail/define.hpp>
+
+ namespace boost { namespace proto
+ {
+ namespace detail
+ {
+
+ template<typename Args>
+ struct by_value_generator_;
+
+ template<typename A>
+ struct by_value_generator_<term<A> >
+ {
+ typedef term<UNCVREF(A)> type;
+
+ template<typename Cons>
+ static typename type::cons_type call(Cons const &a)
+ {
+ typename type::cons_type that = {a.car};
+ return that;
+ }
+ };
+
+ #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
+ template<
+ BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_ARITY, typename A)
+ , typename... Rest
+ >
+ struct by_value_generator_<args<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_ARITY, A), Rest...> >
+ {
+ #define TMP(Z, N, DATA) UNCVREF(A##N)
+ typedef typename cat_args<
+ args<BOOST_PP_ENUM(BOOST_PROTO_MAX_ARITY, TMP, ~) >
+ , typename by_value_generator_<args<Rest...> >::type
+ >::type type;
+ #undef TMP
+
+ template<typename Cons>
+ static typename type::cons_type call(Cons const &a)
+ {
+ #define TMP0(Z, N, DATA) .cdr
+ #define TMP1(Z, N, DATA) {a BOOST_PP_REPEAT_ ## Z(N, TMP0, ~) .car
+ #define TMP2(Z, N, DATA) }
+ typename type::cons_type that =
+ BOOST_PP_ENUM(BOOST_PROTO_MAX_ARITY, TMP1, ~)
+ , by_value_generator_<args<Rest...> >::call(a BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, TMP0, ~))
+ BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, TMP2, ~);
+ return that;
+ #undef TMP0
+ #undef TMP1
+ #undef TMP2
+ }
+ };
+
+ #endif
+
+ #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/xpressive/proto/detail/by_value_generator.hpp>))
+ #include BOOST_PP_ITERATE()
+
+ }
+ }}
+
+ #include <boost/xpressive/proto/detail/undef.hpp>
+ #endif
+
+#else
+
+ template<BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), typename A)>
+ struct by_value_generator_<args<BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)> >
+ {
+ #define TMP(Z, N, DATA) UNCVREF(A##N)
+ typedef args<BOOST_PP_ENUM(BOOST_PP_ITERATION(), TMP, ~) > type;
+ #undef TMP
+
+ template<typename Cons>
+ static typename type::cons_type call(Cons const &a)
+ {
+ #define TMP0(Z, N, DATA) .cdr
+ #define TMP1(Z, N, DATA) {a BOOST_PP_REPEAT_ ## Z(N, TMP0, ~) .car
+ #define TMP2(Z, N, DATA) }
+ typename type::cons_type that =
+ BOOST_PP_ENUM(BOOST_PP_ITERATION(), TMP1, ~)
+ BOOST_PP_REPEAT(BOOST_PP_ITERATION(), TMP2, ~);
+ return that;
+ #undef TMP0
+ #undef TMP1
+ #undef TMP2
+ }
+ };
+
+#endif

Modified: branches/proto/v3/boost/xpressive/proto/generate.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/generate.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/generate.hpp 2007-12-17 16:48:22 EST (Mon, 17 Dec 2007)
@@ -14,62 +14,12 @@
 #include <boost/utility/enable_if.hpp>
 #include <boost/xpressive/proto/proto_fwd.hpp>
 #include <boost/xpressive/proto/matches.hpp>
+#include <boost/xpressive/proto/detail/by_value_generator.hpp>
 #include <boost/xpressive/proto/detail/define.hpp>
 
 namespace boost { namespace proto
 {
 
- namespace detail
- {
- struct by_value_cons
- {
- template<typename Sig>
- struct result;
-
- template<typename This, typename... Args>
- struct result<This(Args...)>
- {
- typedef argsns_::cons<UNCVREF(Args)...> type;
- };
-
- template<typename... Args>
- argsns_::cons<Args...> operator()(Args const &... args) const
- {
- return argsns_::make_cons(std::move(args)...);
- }
- };
-
- template<typename Expr>
- struct by_value_generator_;
-
- template<typename Tag, typename... Args>
- struct by_value_generator_<expr<Tag, args<Args...> > >
- {
- typedef expr<Tag, args<UNCVREF(Args)...> > type;
-
- static type make(expr<Tag, args<Args...> > const &expr)
- {
- type that = {
- argsns_::fanout_args(by_value_cons(), expr.proto_base().proto_args_)
- };
- return that;
- }
- };
-
- template<typename T>
- struct by_value_generator_<expr<tag::terminal, term<T>, 0> >
- {
- typedef expr<tag::terminal, term<UNCVREF(T)> > type;
-
- static type make(expr<tag::terminal, term<T>, 0> const &expr)
- {
- type that = {{expr.proto_base().proto_args_.car}};
- return that;
- }
- };
-
- }
-
     namespace generatorns_
     {
         struct default_generator
@@ -125,15 +75,19 @@
         {
             template<typename Expr>
             struct apply
- : Generator::template apply<
- typename proto::detail::by_value_generator_<Expr>::type
- >
- {};
+ {
+ typedef typename proto::detail::by_value_generator_<typename Expr::proto_args>::type args_type;
+ typedef expr<typename Expr::proto_tag, args_type> expr_type;
+ typedef typename Generator::template apply<expr_type>::type type;
+ };
 
             template<typename Expr>
             static typename apply<Expr>::type make(Expr const &expr)
             {
- return Generator::make(proto::detail::by_value_generator_<Expr>::make(expr));
+ typename apply<Expr>::expr_type that = {
+ proto::detail::by_value_generator_<typename Expr::proto_args>::call(expr.proto_base().proto_args_)
+ };
+ return Generator::make(that);
             }
         };
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk