Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2008-05-28 19:06:14


Author: eric_niebler
Date: 2008-05-28 19:06:13 EDT (Wed, 28 May 2008)
New Revision: 45879
URL: http://svn.boost.org/trac/boost/changeset/45879

Log:
better default handling of operator->*
Text files modified:
   branches/proto/v4/boost/proto/context/default.hpp | 11 ++++-----
   branches/proto/v4/boost/proto/detail/decltype.hpp | 48 ++++++++++++++++++++++++++++++++++++++++
   branches/proto/v4/boost/proto/transform/default.hpp | 11 ++++-----
   3 files changed, 58 insertions(+), 12 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-05-28 19:06:13 EDT (Wed, 28 May 2008)
@@ -155,14 +155,13 @@
                 typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0;
                 typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1;
             public:
- BOOST_PROTO_DECLTYPE_(
- proto::detail::make_mutable<r0>() ->* proto::detail::make<r1>()
- , result_type
- )
+ typedef typename detail::mem_ptr_fun<r0, r1>::result_type result_type;
                 result_type operator ()(Expr &expr, Context &ctx) const
                 {
- return proto::eval(proto::child_c<0>(expr), ctx)
- ->* proto::eval(proto::child_c<1>(expr), ctx);
+ return detail::mem_ptr_fun<r0, r1>()(
+ proto::eval(proto::child_c<0>(expr), ctx)
+ , proto::eval(proto::child_c<1>(expr), ctx)
+ );
                 }
             };
 

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-05-28 19:06:13 EDT (Wed, 28 May 2008)
@@ -18,8 +18,12 @@
 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
 #include <boost/mpl/if.hpp>
 #include <boost/type_traits/remove_cv.hpp>
+#include <boost/type_traits/remove_reference.hpp>
 #include <boost/type_traits/is_pointer.hpp>
 #include <boost/type_traits/is_function.hpp>
+#include <boost/type_traits/is_member_object_pointer.hpp>
+#include <boost/type_traits/add_const.hpp>
+#include <boost/type_traits/add_reference.hpp>
 #include <boost/typeof/typeof.hpp>
 #include <boost/utility/addressof.hpp>
 #include <boost/utility/result_of.hpp>
@@ -126,8 +130,52 @@
             {
                 return boost::addressof(t);
             }
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ template<
+ typename T
+ , typename U
+ , bool IsMemPtr = is_member_object_pointer<
+ typename remove_reference<U>::type
+ >::value
+ >
+ struct mem_ptr_fun
+ {
+ BOOST_PROTO_DECLTYPE_(
+ proto::detail::make_mutable<T>() ->* proto::detail::make<U>()
+ , result_type
+ )
+
+ result_type operator()(
+ typename add_reference<typename add_const<T>::type>::type t
+ , typename add_reference<typename add_const<U>::type>::type u
+ ) const
+ {
+ return t ->* u;
+ }
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ template<typename T, typename U>
+ struct mem_ptr_fun<T, U, true>
+ {
+ BOOST_PROTO_DECLTYPE_(
+ get_pointer(proto::detail::make_mutable<T>()) ->* proto::detail::make<U>()
+ , result_type
+ )
+
+ result_type operator()(
+ typename add_reference<typename add_const<T>::type>::type t
+ , typename add_reference<typename add_const<U>::type>::type u
+ ) const
+ {
+ return get_pointer(t) ->* u;
+ }
+ };
         }
 
+ using get_pointer_::mem_ptr_fun;
+
         ////////////////////////////////////////////////////////////////////////////////////////////
         template<typename A0, typename A1>
         struct comma_result

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-05-28 19:06:13 EDT (Wed, 28 May 2008)
@@ -159,10 +159,7 @@
                 typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
                 typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
             public:
- BOOST_PROTO_DECLTYPE_(
- proto::detail::make_mutable<r0>() ->* proto::detail::make<r1>()
- , result_type
- )
+ typedef typename detail::mem_ptr_fun<r0, r1>::result_type result_type;
                 result_type operator ()(
                     typename memfun_impl::expr_param expr
                   , typename memfun_impl::state_param state
@@ -171,8 +168,10 @@
                 {
                     typename Grammar::template impl<e0, State, Data> t0;
                     typename Grammar::template impl<e1, State, Data> t1;
- return t0(proto::child_c<0>(expr), state, data)
- ->* t1(proto::child_c<1>(expr), state, data);
+ return detail::mem_ptr_fun<r0, r1>()(
+ t0(proto::child_c<0>(expr), state, data)
+ , t1(proto::child_c<1>(expr), state, data)
+ );
                 }
             };
 


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