Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2008-04-22 12:16:20


Author: eric_niebler
Date: 2008-04-22 12:16:19 EDT (Tue, 22 Apr 2008)
New Revision: 44721
URL: http://svn.boost.org/trac/boost/changeset/44721

Log:
default expression evaluators handle member object pointers
Text files modified:
   branches/proto/v4/boost/proto/context/default.hpp | 79 +++++++++++++++++++++++++----
   branches/proto/v4/boost/proto/detail/decltype.hpp | 12 ++++
   branches/proto/v4/boost/proto/transform/default.hpp | 107 +++++++++++++++++++++++++++++++++++----
   3 files changed, 173 insertions(+), 25 deletions(-)

Modified: branches/proto/v4/boost/proto/context/default.hpp
==============================================================================
--- branches/proto/v4/boost/proto/context/default.hpp (original)
+++ branches/proto/v4/boost/proto/context/default.hpp 2008-04-22 12:16:19 EDT (Tue, 22 Apr 2008)
@@ -21,6 +21,8 @@
     #include <boost/type_traits/is_function.hpp>
     #include <boost/type_traits/remove_reference.hpp>
     #include <boost/type_traits/is_member_pointer.hpp>
+ #include <boost/type_traits/is_member_object_pointer.hpp>
+ #include <boost/type_traits/is_member_function_pointer.hpp>
     #include <boost/proto/proto_fwd.hpp>
     #include <boost/proto/tags.hpp>
     #include <boost/proto/eval.hpp>
@@ -239,14 +241,73 @@
             // Handle function specially
             #define EVAL_TYPE(Z, N, DATA) \
                 typename proto::result_of::eval< \
- typename remove_reference<typename proto::result_of::child_c<DATA, N>::type>::type\
+ typename remove_reference< \
+ typename proto::result_of::child_c<DATA, N>::type \
+ >::type \
                   , Context \
- >::type
+ >::type \
+ /**/
 
             #define EVAL(Z, N, DATA) \
- proto::eval(proto::child_c<N>(DATA), context)
+ proto::eval(proto::child_c<N>(DATA), context) \
+ /**/
+
+ template<typename Expr, typename Context>
+ struct default_eval<Expr, Context, proto::tag::function, 1>
+ {
+ typedef
+ typename proto::detail::result_of_fixup<EVAL_TYPE(~, 0, Expr)>::type
+ function_type;
+
+ typedef
+ typename boost::result_of<function_type()>::type
+ result_type;
+
+ result_type operator ()(Expr &expr, Context &context) const
+ {
+ return EVAL(~, 0, expr)();
+ }
+ };
+
+ template<typename Expr, typename Context>
+ struct default_eval<Expr, Context, proto::tag::function, 2>
+ {
+ typedef
+ typename proto::detail::result_of_fixup<EVAL_TYPE(~, 0, Expr)>::type
+ function_type;
+
+ typedef
+ typename detail::result_of_<function_type(EVAL_TYPE(~, 1, Expr))>::type
+ result_type;
 
- #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/context/default.hpp>))
+ result_type operator ()(Expr &expr, Context &context) const
+ {
+ return this->invoke(
+ expr
+ , context
+ , is_member_function_pointer<function_type>()
+ , is_member_object_pointer<function_type>()
+ );
+ }
+
+ private:
+ result_type invoke(Expr &expr, Context &context, mpl::false_, mpl::false_) const
+ {
+ return EVAL(~, 0, expr)(EVAL(~, 1, expr));
+ }
+
+ result_type invoke(Expr &expr, Context &context, mpl::true_, mpl::false_) const
+ {
+ return (detail::deref(EVAL(~, 1, expr)) .* EVAL(~, 0, expr))();
+ }
+
+ result_type invoke(Expr &expr, Context &context, mpl::false_, mpl::true_) const
+ {
+ return (detail::deref(EVAL(~, 1, expr)) .* EVAL(~, 0, expr));
+ }
+ };
+
+ #define BOOST_PP_ITERATION_PARAMS_1 (3, (3, BOOST_PROTO_MAX_ARITY, <boost/proto/context/default.hpp>))
             #include BOOST_PP_ITERATE()
 
             #undef EVAL_TYPE
@@ -289,17 +350,12 @@
>::type
             result_type;
 
- #if N == 1
- result_type operator ()(Expr &expr, Context &context) const
- {
- return EVAL(~, 0, expr)(BOOST_PP_ENUM_SHIFTED(N, EVAL, expr));
- }
- #else
             result_type operator ()(Expr &expr, Context &context) const
             {
- return this->invoke(expr, context, is_member_pointer<function_type>());
+ return this->invoke(expr, context, is_member_function_pointer<function_type>());
             }
 
+ private:
             result_type invoke(Expr &expr, Context &context, mpl::false_) const
             {
                 return EVAL(~, 0, expr)(BOOST_PP_ENUM_SHIFTED(N, EVAL, expr));
@@ -313,7 +369,6 @@
                 );
                 #undef M0
             }
- #endif
         };
 
     #undef N

Modified: branches/proto/v4/boost/proto/detail/decltype.hpp
==============================================================================
--- branches/proto/v4/boost/proto/detail/decltype.hpp (original)
+++ branches/proto/v4/boost/proto/detail/decltype.hpp 2008-04-22 12:16:19 EDT (Tue, 22 Apr 2008)
@@ -133,6 +133,18 @@
         };
 
         ////////////////////////////////////////////////////////////////////////////////////////////
+ template<typename T>
+ struct result_of_
+ : boost::result_of<T>
+ {};
+
+ template<typename T, typename U, typename V>
+ struct result_of_<T U::*(V)>
+ {
+ typedef T type;
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
         template<typename T, typename U = T>
         struct result_of_fixup
           : mpl::if_c<is_function<T>::value, T *, U>

Modified: branches/proto/v4/boost/proto/transform/default.hpp
==============================================================================
--- branches/proto/v4/boost/proto/transform/default.hpp (original)
+++ branches/proto/v4/boost/proto/transform/default.hpp 2008-04-22 12:16:19 EDT (Tue, 22 Apr 2008)
@@ -19,6 +19,8 @@
     #include <boost/ref.hpp>
     #include <boost/utility/enable_if.hpp>
     #include <boost/type_traits/is_member_pointer.hpp>
+ #include <boost/type_traits/is_member_object_pointer.hpp>
+ #include <boost/type_traits/is_member_function_pointer.hpp>
     #include <boost/proto/proto_fwd.hpp>
     #include <boost/proto/traits.hpp>
     #include <boost/proto/transform/impl.hpp>
@@ -274,7 +276,96 @@
                 ) \
                 /**/
 
- #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/transform/default.hpp>))
+ template<typename Expr, typename State, typename Data>
+ struct impl2<Expr, State, Data, tag::function, 1>
+ : transform_impl<Expr, State, Data>
+ {
+ EVAL_TYPE(~, 0, Expr)
+
+ typedef
+ typename proto::detail::result_of_fixup<r0>::type
+ function_type;
+
+ typedef
+ typename boost::result_of<function_type()>::type
+ result_type;
+
+ result_type operator ()(
+ typename impl2::expr_param expr
+ , typename impl2::state_param state
+ , typename impl2::data_param data
+ ) const
+ {
+ return EVAL(~, 0, expr)();
+ }
+ };
+
+ template<typename Expr, typename State, typename Data>
+ struct impl2<Expr, State, Data, tag::function, 2>
+ : transform_impl<Expr, State, Data>
+ {
+ EVAL_TYPE(~, 0, Expr)
+ EVAL_TYPE(~, 1, Expr)
+
+ typedef
+ typename proto::detail::result_of_fixup<r0>::type
+ function_type;
+
+ typedef
+ typename detail::result_of_<function_type(r1)>::type
+ result_type;
+
+ result_type operator ()(
+ typename impl2::expr_param expr
+ , typename impl2::state_param state
+ , typename impl2::data_param data
+ ) const
+ {
+ return this->invoke(
+ expr
+ , state
+ , data
+ , is_member_function_pointer<function_type>()
+ , is_member_object_pointer<function_type>()
+ );
+ }
+
+ private:
+ result_type invoke(
+ typename impl2::expr_param expr
+ , typename impl2::state_param state
+ , typename impl2::data_param data
+ , mpl::false_
+ , mpl::false_
+ ) const
+ {
+ return EVAL(~, 0, expr)(EVAL(~, 1, expr));
+ }
+
+ result_type invoke(
+ typename impl2::expr_param expr
+ , typename impl2::state_param state
+ , typename impl2::data_param data
+ , mpl::true_
+ , mpl::false_
+ ) const
+ {
+ return (detail::deref(EVAL(~, 1, expr)) .* EVAL(~, 0, expr))();
+ }
+
+ result_type invoke(
+ typename impl2::expr_param expr
+ , typename impl2::state_param state
+ , typename impl2::data_param data
+ , mpl::false_
+ , mpl::true_
+ ) const
+ {
+ return (detail::deref(EVAL(~, 1, expr)) .* EVAL(~, 0, expr));
+ }
+ };
+
+ #define BOOST_PP_ITERATION_PARAMS_1 (3, (3, BOOST_PROTO_MAX_ARITY, <boost/proto/transform/default.hpp>))
             #include BOOST_PP_ITERATE()
 
             #undef EVAL_TYPE
@@ -321,25 +412,16 @@
>::type
             result_type;
 
- #if N == 1
- result_type operator ()(
- typename impl2::expr_param expr
- , typename impl2::state_param state
- , typename impl2::data_param data
- ) const
- {
- return EVAL(~, 0, expr)(BOOST_PP_ENUM_SHIFTED(N, EVAL, expr));
- }
- #else
             result_type operator ()(
                 typename impl2::expr_param expr
               , typename impl2::state_param state
               , typename impl2::data_param data
             ) const
             {
- return this->invoke(expr, state, data, is_member_pointer<function_type>());
+ return this->invoke(expr, state, data, is_member_function_pointer<function_type>());
             }
 
+ private:
             result_type invoke(
                 typename impl2::expr_param expr
               , typename impl2::state_param state
@@ -363,7 +445,6 @@
                 );
                 #undef M0
             }
- #endif
         };
 
     #undef N


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