Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-12-02 20:45:16


Author: eric_niebler
Date: 2007-12-02 20:45:15 EST (Sun, 02 Dec 2007)
New Revision: 41623
URL: http://svn.boost.org/trac/boost/changeset/41623

Log:
add make<> transform
Added:
   branches/proto/v3/boost/xpressive/proto/transform/make.hpp (contents, props changed)
Text files modified:
   branches/proto/v3/boost/xpressive/detail/static/grammar.hpp | 6
   branches/proto/v3/boost/xpressive/proto/proto_fwd.hpp | 11 +
   branches/proto/v3/boost/xpressive/proto/transform/when.hpp | 168 +++++----------------------------------
   3 files changed, 33 insertions(+), 152 deletions(-)

Modified: branches/proto/v3/boost/xpressive/detail/static/grammar.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/static/grammar.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/static/grammar.hpp 2007-12-02 20:45:15 EST (Sun, 02 Dec 2007)
@@ -567,13 +567,13 @@
 
             template<typename Greedy>
             struct as_simple_repeat
- : call< // TODO add a make<> transform
- _(simple_repeat_matcher<as_independent(_arg), Greedy>(
+ : make<
+ simple_repeat_matcher<as_independent(_arg), Greedy>(
                         as_independent(_arg)
                       , min_type<tag_of<_> >()
                       , max_type<tag_of<_> >()
                       , get_width(as_independent(_arg))
- ))
+ )
>
             {};
 

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-02 20:45:15 EST (Sun, 02 Dec 2007)
@@ -11,6 +11,7 @@
 
 #include <climits> // for INT_MAX
 #include <boost/type_traits.hpp>
+#include <boost/mpl/bool.hpp>
 #include <boost/mpl/aux_/template_arity.hpp>
 #include <boost/mpl/aux_/lambda_arity_param.hpp>
 
@@ -339,9 +340,15 @@
             typedef void proto_is_transform_;
         };
 
+ template<typename Grammar, typename Fun = Grammar>
+ struct when;
+
         template<typename Fun, typename... Args>
         struct call;
 
+ template<typename Fun, typename... Args>
+ struct make;
+
         template<typename Sequence, typename State, typename Fun>
         struct fold;
 
@@ -355,9 +362,6 @@
         template<typename Sequence, typename State, typename Fun>
         struct reverse_fold_tree;
 
- template<typename Grammar, typename Fun = Grammar>
- struct when;
-
         struct _expr;
         struct _state;
         struct _visitor;
@@ -403,6 +407,7 @@
     using transform::_visitor;
     using transform::_arg_c;
     using transform::call;
+ using transform::make;
     using transform::fold;
     using transform::always;
     using transform::reverse_fold;

Added: branches/proto/v3/boost/xpressive/proto/transform/make.hpp
==============================================================================
--- (empty file)
+++ branches/proto/v3/boost/xpressive/proto/transform/make.hpp 2007-12-02 20:45:15 EST (Sun, 02 Dec 2007)
@@ -0,0 +1,159 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file make.hpp
+/// Contains definition of the make<> transform.
+//
+// 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_TRANSFORM_MAKE_HPP_EAN_12_02_2007
+#define BOOST_PROTO_TRANSFORM_MAKE_HPP_EAN_12_02_2007
+
+#include <boost/mpl/aux_/has_type.hpp>
+#include <boost/utility/result_of.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/xpressive/proto/proto_fwd.hpp>
+#include <boost/xpressive/proto/traits.hpp>
+
+namespace boost { namespace proto
+{
+
+ namespace transform
+ {
+ namespace detail
+ {
+ template<typename... T>
+ struct typelist
+ {
+ typedef void type;
+ };
+
+ template<typename T, bool HasType = mpl::aux::has_type<T>::value>
+ struct nested_type
+ {
+ typedef typename T::type type;
+ };
+
+ template<typename T>
+ struct nested_type<T, false>
+ {
+ typedef T type;
+ };
+
+ template<typename T, typename Args, typename EnableIf = void>
+ struct nested_type_if
+ : nested_type<T>
+ {};
+
+ template<typename T, typename... Args>
+ struct nested_type_if<T, typelist<Args...>, typename typelist<typename Args::not_applied_...>::type>
+ {
+ typedef T type;
+ typedef void not_applied_;
+ };
+
+ template<typename R, typename Expr, typename State, typename Visitor
+ , bool IsTransform = is_transform<R>::value
+ >
+ struct apply_lambda_;
+
+ template<typename R, typename Expr, typename State, typename Visitor>
+ struct apply_lambda_aux_
+ {
+ typedef R type;
+ typedef void not_applied_;
+ };
+
+ template<template<typename...> class R, typename... Args, typename Expr, typename State, typename Visitor>
+ struct apply_lambda_aux_<R<Args...>, Expr, State, Visitor>
+ : nested_type_if<
+ R<typename apply_lambda_<Args, Expr, State, Visitor>::type...>
+ , typelist<apply_lambda_<Args, Expr, State, Visitor>...>
+ >
+ {};
+
+ template<typename R, typename Expr, typename State, typename Visitor>
+ struct apply_lambda_<R, Expr, State, Visitor, false>
+ : apply_lambda_aux_<R, Expr, State, Visitor>
+ {};
+
+ template<typename R, typename Expr, typename State, typename Visitor>
+ struct apply_lambda_<R, Expr, State, Visitor, true>
+ : boost::result_of<R(Expr, State, Visitor)>
+ {};
+
+ template<typename R, typename... Args, typename Expr, typename State, typename Visitor>
+ struct apply_lambda_<R(Args...), Expr, State, Visitor, false>
+ : boost::result_of<when<_, R(Args...)>(Expr, State, Visitor)>
+ {};
+
+ template<typename R, typename... Args, typename Expr, typename State, typename Visitor>
+ struct apply_lambda_<R(*)(Args...), Expr, State, Visitor, false>
+ : boost::result_of<when<_, R(*)(Args...)>(Expr, State, Visitor)>
+ {};
+
+ // work around GCC bug
+ template<typename Tag, typename Args, long N, typename Expr, typename State, typename Visitor>
+ struct apply_lambda_<expr<Tag, Args, N>, Expr, State, Visitor, false>
+ {
+ typedef expr<Tag, Args, N> type;
+ typedef void not_applied_;
+ };
+
+ template<typename Type, typename... Args>
+ typename enable_if<is_aggregate<Type>, Type>::type
+ construct_(Args &&... args)
+ {
+ Type that = { args... };
+ return that;
+ }
+
+ template<typename Type, typename... Args>
+ typename disable_if<is_aggregate<Type>, Type>::type
+ construct_(Args &&... args)
+ {
+ return Type(args...);
+ }
+
+ template<typename Type>
+ Type construct_()
+ {
+ return Type();
+ }
+ }
+
+ template<typename Return, typename... Args>
+ struct make : transform_base
+ {
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename Expr, typename State, typename Visitor>
+ struct result<This(Expr, State, Visitor)>
+ : detail::apply_lambda_<Return, Expr, State, Visitor>
+ {};
+
+ template<typename Expr, typename State, typename Visitor>
+ typename result<make(Expr, State, Visitor)>::type
+ operator()(Expr const &expr, State const &state, Visitor &visitor) const
+ {
+ typedef typename result<make(Expr, State, Visitor)>::type result_type;
+ return detail::construct_<result_type>(when<_, Args>()(expr, state, visitor)...);
+ }
+ };
+
+ template<typename Fun, typename... Args>
+ struct make<Fun(Args...)>
+ : make<Fun, Args...>
+ {};
+
+ }
+
+ template<typename Fun, typename... Args>
+ struct is_transform<transform::make<Fun, Args...> >
+ : mpl::true_
+ {};
+
+}}
+
+#endif

Modified: branches/proto/v3/boost/xpressive/proto/transform/when.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/transform/when.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/transform/when.hpp 2007-12-02 20:45:15 EST (Sun, 02 Dec 2007)
@@ -9,15 +9,13 @@
 #ifndef BOOST_PROTO_TRANSFORM_CASE_HPP_EAN_10_29_2007
 #define BOOST_PROTO_TRANSFORM_CASE_HPP_EAN_10_29_2007
 
+#include <boost/mpl/if.hpp>
 #include <boost/mpl/bool.hpp>
-#include <boost/mpl/logical.hpp>
-#include <boost/mpl/eval_if.hpp>
-#include <boost/mpl/identity.hpp>
-#include <boost/mpl/aux_/has_type.hpp>
 #include <boost/type_traits.hpp>
-#include <boost/utility/enable_if.hpp>
 #include <boost/xpressive/proto/proto_fwd.hpp>
+#include <boost/xpressive/proto/traits.hpp>
 #include <boost/xpressive/proto/transform/call.hpp>
+#include <boost/xpressive/proto/transform/make.hpp>
 
 namespace boost { namespace proto
 {
@@ -69,105 +67,7 @@
     {
         namespace detail
         {
- template<typename... T>
- struct typelist
- {
- typedef void type;
- };
-
- template<typename T, bool HasType = mpl::aux::has_type<T>::value>
- struct nested_type
- {
- typedef typename T::type type;
- };
-
- template<typename T>
- struct nested_type<T, false>
- {
- typedef T type;
- };
-
- template<typename T, typename Args, typename EnableIf = void>
- struct nested_type_if
- : nested_type<T>
- {};
-
- template<typename T, typename... Args>
- struct nested_type_if<T, typelist<Args...>, typename typelist<typename Args::not_applied_...>::type>
- {
- typedef T type;
- typedef void not_applied_;
- };
-
- template<typename R, typename Expr, typename State, typename Visitor
- , bool IsTransform = is_transform<R>::value
- >
- struct apply_lambda_;
-
- template<typename R, typename Expr, typename State, typename Visitor>
- struct apply_lambda_aux_
- {
- typedef R type;
- typedef void not_applied_;
- };
-
- template<template<typename...> class R, typename... Args, typename Expr, typename State, typename Visitor>
- struct apply_lambda_aux_<R<Args...>, Expr, State, Visitor>
- : nested_type_if<
- R<typename apply_lambda_<Args, Expr, State, Visitor>::type...>
- , typelist<apply_lambda_<Args, Expr, State, Visitor>...>
- >
- {};
-
- template<typename R, typename Expr, typename State, typename Visitor>
- struct apply_lambda_<R, Expr, State, Visitor, false>
- : apply_lambda_aux_<R, Expr, State, Visitor>
- {};
-
- template<typename R, typename Expr, typename State, typename Visitor>
- struct apply_lambda_<R, Expr, State, Visitor, true>
- : boost::result_of<R(Expr, State, Visitor)>
- {};
-
- template<typename R, typename... Args, typename Expr, typename State, typename Visitor>
- struct apply_lambda_<R(Args...), Expr, State, Visitor, false>
- : boost::result_of<when<_, R(Args...)>(Expr, State, Visitor)>
- {};
-
- template<typename R, typename... Args, typename Expr, typename State, typename Visitor>
- struct apply_lambda_<R(*)(Args...), Expr, State, Visitor, false>
- : boost::result_of<when<_, R(*)(Args...)>(Expr, State, Visitor)>
- {};
-
- // work around GCC bug
- template<typename Tag, typename Args, long N, typename Expr, typename State, typename Visitor>
- struct apply_lambda_<expr<Tag, Args, N>, Expr, State, Visitor, false>
- {
- typedef expr<Tag, Args, N> type;
- typedef void not_applied_;
- };
-
- template<typename Type, typename... Args>
- typename enable_if<is_aggregate<Type>, Type>::type
- construct_(Args &&... args)
- {
- Type that = { args... };
- return that;
- }
-
- template<typename Type, typename... Args>
- typename disable_if<is_aggregate<Type>, Type>::type
- construct_(Args &&... args)
- {
- return Type(args...);
- }
-
- template<typename Type>
- Type construct_()
- {
- return Type();
- }
-
+ // can't this apply template be always used? What is the purpose of the one below?
             template<
                 typename Expr
               , typename State
@@ -178,34 +78,27 @@
>
             struct apply
             {
- typedef typename apply_lambda_<Return, Expr, State, Visitor>::type lambda_type;
+ typedef
+ typename boost::result_of<
+ transform::make<Return, Args...>(Expr, State, Visitor)
+ >::type
+ lambda_type;
 
                 // If the result of applying the lambda on the return type is a transform,
                 // apply the transform rather than trying to construct it.
                 typedef
- typename mpl::eval_if<
+ typename mpl::if_<
                         proto::detail::is_transform2_<lambda_type>
- , apply<Expr, State, Visitor, true, lambda_type, Args...>
- , mpl::identity<lambda_type>
+ , transform::call<lambda_type, Args...>
+ , transform::make<Return, Args...>
>::type
- type;
-
- static type call(Expr const &expr, State const &state, Visitor &visitor)
- {
- return apply::call_(expr, state, visitor, proto::detail::is_transform2_<lambda_type>());
- }
+ transform_type;
 
- private:
- static type call_(Expr const &expr, State const &state, Visitor &visitor, mpl::false_)
- {
- return detail::construct_<type>(
- when<_, Args>()(expr, state, visitor)...
- );
- }
+ typedef typename boost::result_of<transform_type(Expr, State, Visitor)>::type type;
 
- static type call_(Expr const &expr, State const &state, Visitor &visitor, mpl::true_)
+ static type call(Expr const &expr, State const &state, Visitor &visitor)
                 {
- return apply<Expr, State, Visitor, true, lambda_type, Args...>::call(expr, state, visitor);
+ return transform_type()(expr, state, visitor);
                 }
             };
 
@@ -239,6 +132,12 @@
             typedef typename Grammar::proto_base_expr proto_base_expr;
         };
 
+ // Function-style transforms, handled below...
+ template<typename Grammar, typename Return, typename... Args>
+ struct when<Grammar, Return(*)(Args...)>
+ : when<Grammar, Return(Args...)>
+ {};
+
         // Lambda-style transform, takes a raw or function-style
         // transform with arguments and applies it, OR takes a
         // (possibly lambda) type and constructor arguments.
@@ -256,29 +155,6 @@
               : detail::apply<Expr, State, Visitor, is_transform<Return>::value, Return, Args...>
             {};
 
- // BUGBUG makes a temporary
- template<typename Expr, typename State, typename Visitor>
- typename result<when(Expr, State, Visitor)>::type
- operator()(Expr const &expr, State const &state, Visitor &visitor) const
- {
- return result<when(Expr, State, Visitor)>::call(expr, state, visitor);
- }
- };
-
- template<typename Grammar, typename Return, typename... Args>
- struct when<Grammar, Return(*)(Args...)>
- : transform_base
- {
- typedef typename Grammar::proto_base_expr proto_base_expr;
-
- template<typename Sig>
- struct result;
-
- template<typename This, typename Expr, typename State, typename Visitor>
- struct result<This(Expr, State, Visitor)>
- : detail::apply<Expr, State, Visitor, is_transform<Return>::value, Return, Args...>
- {};
-
             template<typename Expr, typename State, typename Visitor>
             typename result<when(Expr, State, Visitor)>::type
             operator()(Expr const &expr, State const &state, Visitor &visitor) const


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