Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62798 - in trunk/boost/proto: . detail
From: eric_at_[hidden]
Date: 2010-06-11 09:49:00


Author: eric_niebler
Date: 2010-06-11 09:49:00 EDT (Fri, 11 Jun 2010)
New Revision: 62798
URL: http://svn.boost.org/trac/boost/changeset/62798

Log:
attempt to fix portability regression, eliminate unnecessary is_expr instantiations
Text files modified:
   trunk/boost/proto/detail/as_expr.hpp | 237 ++++++++++++++++-----------------------
   trunk/boost/proto/domain.hpp | 43 ++++++-
   trunk/boost/proto/traits.hpp | 28 ++--
   3 files changed, 150 insertions(+), 158 deletions(-)

Modified: trunk/boost/proto/detail/as_expr.hpp
==============================================================================
--- trunk/boost/proto/detail/as_expr.hpp (original)
+++ trunk/boost/proto/detail/as_expr.hpp 2010-06-11 09:49:00 EDT (Fri, 11 Jun 2010)
@@ -11,29 +11,11 @@
 #ifndef BOOST_PROTO_DETAIL_AS_EXPR_HPP_EAN_06_09_2010
 #define BOOST_PROTO_DETAIL_AS_EXPR_HPP_EAN_06_09_2010
 
-#include <boost/type_traits/is_same.hpp>
 #include <boost/proto/proto_fwd.hpp>
 #include <boost/proto/args.hpp>
 
 namespace boost { namespace proto { namespace detail
 {
- ////////////////////////////////////////////////////////////////////////////////////////////////
- template<
- typename T
- , typename Generator
- , bool IsExpr = is_expr<T>::value
- , bool WantsBasicExpr = wants_basic_expr<Generator>::value
- >
- struct as_expr;
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
- template<
- typename T
- , typename Generator
- , bool IsExpr = is_expr<T>::value
- , bool WantsBasicExpr = wants_basic_expr<Generator>::value
- >
- struct as_child;
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
     template<typename Generator>
@@ -49,6 +31,64 @@
     };
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
+ template<typename T, typename Generator, bool WantsBasicExpr>
+ struct as_expr;
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////
+ template<typename T, typename Generator>
+ struct as_expr<T, Generator, false>
+ {
+ typedef typename term_traits<T &>::value_type value_type;
+ typedef proto::expr<proto::tag::terminal, term<value_type>, 0> expr_type;
+ typedef typename Generator::template result<Generator(expr_type)>::type result_type;
+
+ result_type operator()(T &t) const
+ {
+ return Generator()(expr_type::make(t));
+ }
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////
+ template<typename T, typename Generator>
+ struct as_expr<T, Generator, true>
+ {
+ typedef typename term_traits<T &>::value_type value_type;
+ typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> expr_type;
+ typedef typename Generator::template result<Generator(expr_type)>::type result_type;
+
+ result_type operator()(T &t) const
+ {
+ return Generator()(expr_type::make(t));
+ }
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////
+ template<typename T>
+ struct as_expr<T, proto::default_generator, false>
+ {
+ typedef typename term_traits<T &>::value_type value_type;
+ typedef proto::expr<proto::tag::terminal, term<value_type>, 0> result_type;
+
+ result_type operator()(T &t) const
+ {
+ return result_type::make(t);
+ }
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////
+ template<typename T>
+ struct as_expr<T, proto::default_generator, true>
+ {
+ typedef typename term_traits<T &>::value_type value_type;
+ typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> result_type;
+
+ result_type operator()(T &t) const
+ {
+ return result_type::make(t);
+ }
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////
     template<typename Expr, typename Generator, bool SameGenerator>
     struct already_expr
     {
@@ -65,7 +105,7 @@
     template<typename Expr, typename Generator>
     struct already_expr<Expr, Generator, true>
     {
- typedef typename Expr::proto_derived_expr result_type;
+ typedef typename Expr::proto_derived_expr result_type; // remove cv
 
         result_type operator()(Expr &e) const
         {
@@ -74,23 +114,22 @@
     };
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename Expr, typename Generator, bool SameGenerator>
- struct already_child
+ template<typename Expr>
+ struct already_expr<Expr, default_generator, false>
     {
- typedef typename Expr::proto_derived_expr uncv_expr_type;
- typedef typename Generator::template result<Generator(uncv_expr_type)>::type result_type;
+ typedef typename Expr::proto_derived_expr result_type; // remove cv
 
         result_type operator()(Expr &e) const
         {
- return Generator()(e);
+ return e;
         }
     };
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename Expr, typename Generator>
- struct already_child<Expr, Generator, true>
+ template<typename Expr>
+ struct already_expr<Expr, default_generator, true>
     {
- typedef Expr &result_type;
+ typedef typename Expr::proto_derived_expr result_type; // remove cv
 
         result_type operator()(Expr &e) const
         {
@@ -99,11 +138,14 @@
     };
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
+ template<typename T, typename Generator, bool WantsBasicExpr>
+ struct as_child;
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////
     template<typename T, typename Generator>
- struct as_expr<T, Generator, false, false>
+ struct as_child<T, Generator, false>
     {
- typedef typename term_traits<T &>::value_type value_type;
- typedef proto::expr<proto::tag::terminal, term<value_type>, 0> expr_type;
+ typedef proto::expr<proto::tag::terminal, term<T &>, 0> expr_type;
         typedef typename Generator::template result<Generator(expr_type)>::type result_type;
 
         result_type operator()(T &t) const
@@ -114,10 +156,9 @@
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
     template<typename T, typename Generator>
- struct as_expr<T, Generator, false, true>
+ struct as_child<T, Generator, true>
     {
- typedef typename term_traits<T &>::value_type value_type;
- typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> expr_type;
+ typedef proto::basic_expr<proto::tag::terminal, term<T &>, 0> expr_type;
         typedef typename Generator::template result<Generator(expr_type)>::type result_type;
 
         result_type operator()(T &t) const
@@ -127,37 +168,10 @@
     };
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T, typename Generator>
- struct as_expr<T, Generator, true, false>
- : already_expr<
- T
- , Generator
- , is_same<
- Generator
- , typename base_generator<typename T::proto_generator>::type
- >::value
- >
- {};
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T, typename Generator>
- struct as_expr<T, Generator, true, true>
- : already_expr<
- T
- , Generator
- , is_same<
- Generator
- , typename base_generator<typename T::proto_generator>::type
- >::value
- >
- {};
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
     template<typename T>
- struct as_expr<T, proto::default_generator, false, false>
+ struct as_child<T, proto::default_generator, false>
     {
- typedef typename term_traits<T &>::value_type value_type;
- typedef proto::expr<proto::tag::terminal, term<value_type>, 0> result_type;
+ typedef proto::expr<proto::tag::terminal, term<T &>, 0> result_type;
 
         result_type operator()(T &t) const
         {
@@ -167,10 +181,9 @@
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
     template<typename T>
- struct as_expr<T, proto::default_generator, false, true>
+ struct as_child<T, proto::default_generator, true>
     {
- typedef typename term_traits<T &>::value_type value_type;
- typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> result_type;
+ typedef proto::basic_expr<proto::tag::terminal, term<T &>, 0> result_type;
 
         result_type operator()(T &t) const
         {
@@ -179,106 +192,54 @@
     };
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T>
- struct as_expr<T, proto::default_generator, true, false>
- : already_expr<T, proto::default_generator, true>
- {};
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T>
- struct as_expr<T, proto::default_generator, true, true>
- : already_expr<T, proto::default_generator, true>
- {};
-
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T, typename Generator>
- struct as_child<T, Generator, false, false>
+ template<typename Expr, typename Generator, bool SameGenerator>
+ struct already_child
     {
- typedef proto::expr<proto::tag::terminal, term<T &>, 0> expr_type;
- typedef typename Generator::template result<Generator(expr_type)>::type result_type;
+ typedef typename Expr::proto_derived_expr uncv_expr_type;
+ typedef typename Generator::template result<Generator(uncv_expr_type)>::type result_type;
 
- result_type operator()(T &t) const
+ result_type operator()(Expr &e) const
         {
- return Generator()(expr_type::make(t));
+ return Generator()(e);
         }
     };
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T, typename Generator>
- struct as_child<T, Generator, false, true>
+ template<typename Expr, typename Generator>
+ struct already_child<Expr, Generator, true>
     {
- typedef proto::basic_expr<proto::tag::terminal, term<T &>, 0> expr_type;
- typedef typename Generator::template result<Generator(expr_type)>::type result_type;
+ typedef Expr &result_type;
 
- result_type operator()(T &t) const
+ result_type operator()(Expr &e) const
         {
- return Generator()(expr_type::make(t));
+ return e;
         }
     };
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T, typename Generator>
- struct as_child<T, Generator, true, false>
- : already_child<
- T
- , Generator
- , is_same<
- Generator
- , typename base_generator<typename T::proto_generator>::type
- >::value
- >
- {};
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T, typename Generator>
- struct as_child<T, Generator, true, true>
- : already_child<
- T
- , Generator
- , is_same<
- Generator
- , typename base_generator<typename T::proto_generator>::type
- >::value
- >
- {};
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T>
- struct as_child<T, proto::default_generator, false, false>
+ template<typename Expr>
+ struct already_child<Expr, default_generator, false>
     {
- typedef proto::expr<proto::tag::terminal, term<T &>, 0> result_type;
+ typedef Expr &result_type;
 
- result_type operator()(T &t) const
+ result_type operator()(Expr &e) const
         {
- return result_type::make(t);
+ return e;
         }
     };
 
     ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T>
- struct as_child<T, proto::default_generator, false, true>
+ template<typename Expr>
+ struct already_child<Expr, default_generator, true>
     {
- typedef proto::basic_expr<proto::tag::terminal, term<T &>, 0> result_type;
+ typedef Expr &result_type;
 
- result_type operator()(T &t) const
+ result_type operator()(Expr &e) const
         {
- return result_type::make(t);
+ return e;
         }
     };
 
- ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T>
- struct as_child<T, proto::default_generator, true, false>
- : already_child<T, proto::default_generator, true>
- {};
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
- template<typename T>
- struct as_child<T, proto::default_generator, true, true>
- : already_child<T, proto::default_generator, true>
- {};
-
 }}}
 
 #endif

Modified: trunk/boost/proto/domain.hpp
==============================================================================
--- trunk/boost/proto/domain.hpp (original)
+++ trunk/boost/proto/domain.hpp 2010-06-11 09:49:00 EDT (Fri, 11 Jun 2010)
@@ -12,6 +12,7 @@
 #define BOOST_PROTO_DOMAIN_HPP_EAN_02_13_2007
 
 #include <boost/ref.hpp>
+#include <boost/type_traits/is_same.hpp>
 #include <boost/proto/proto_fwd.hpp>
 #include <boost/proto/generate.hpp>
 #include <boost/proto/detail/as_expr.hpp>
@@ -96,7 +97,7 @@
         /// INTERNAL ONLY
         typedef void proto_is_domain_;
 
- /// \brief A monomorphic unary function object that turns objects into Proto
+ /// \brief A unary MonomorphicFunctionObject that turns objects into Proto
         /// expression objects in this domain.
         ///
         /// The <tt>as_expr\<\></tt> function object turns objects into Proto expressions, if
@@ -120,19 +121,34 @@
         ///
         /// Otherwise, the result is \c t converted to an (un-const) rvalue.
         ///
- template<typename T, typename Callable = proto::callable>
+ template<typename T, typename IsExpr = void, typename Callable = proto::callable>
         struct as_expr
           : detail::as_expr<
                 T
               , typename detail::base_generator<Generator>::type
- , is_expr<T>::value
               , wants_basic_expr<Generator>::value
>
         {
             BOOST_PROTO_CALLABLE()
         };
 
- /// \brief A monomorphic unary function object that turns objects into Proto
+ /// INTERNAL ONLY
+ ///
+ template<typename T>
+ struct as_expr<T, typename T::proto_is_expr_, proto::callable>
+ : detail::already_expr<
+ T
+ , typename detail::base_generator<Generator>::type
+ , is_same<
+ typename detail::base_generator<Generator>::type
+ , typename detail::base_generator<typename T::proto_generator>::type
+ >::value
+ >
+ {
+ BOOST_PROTO_CALLABLE()
+ };
+
+ /// \brief A unary MonomorphicFunctionObject that turns objects into Proto
         /// expression objects in this domain.
         ///
         /// The <tt>as_child\<\></tt> function object turns objects into Proto expressions, if
@@ -150,17 +166,32 @@
         ///
         /// Otherwise, the result is the lvalue \c t.
         ///
- template<typename T, typename Callable = proto::callable>
+ template<typename T, typename IsExpr = void, typename Callable = proto::callable>
         struct as_child
           : detail::as_child<
                 T
               , typename detail::base_generator<Generator>::type
- , is_expr<T>::value
               , wants_basic_expr<Generator>::value
>
         {
             BOOST_PROTO_CALLABLE()
         };
+
+ /// INTERNAL ONLY
+ ///
+ template<typename T>
+ struct as_child<T, typename T::proto_is_expr_, proto::callable>
+ : detail::already_child<
+ T
+ , typename detail::base_generator<Generator>::type
+ , is_same<
+ typename detail::base_generator<Generator>::type
+ , typename detail::base_generator<typename T::proto_generator>::type
+ >::value
+ >
+ {
+ BOOST_PROTO_CALLABLE()
+ };
     };
 
     /// \brief The domain expressions have by default, if

Modified: trunk/boost/proto/traits.hpp
==============================================================================
--- trunk/boost/proto/traits.hpp (original)
+++ trunk/boost/proto/traits.hpp 2010-06-11 09:49:00 EDT (Fri, 11 Jun 2010)
@@ -630,7 +630,7 @@
                 /// \param t The object to wrap.
                 /// \return <tt>proto::as_expr\<Domain\>(t)</tt>
                 template<typename T>
- typename Domain::template as_expr<T>::result_type
+ typename result<as_expr(T &)>::type
                 operator ()(T &t) const
                 {
                     return typename Domain::template as_expr<T>()(t);
@@ -639,7 +639,7 @@
                 /// \overload
                 ///
                 template<typename T>
- typename Domain::template as_expr<T const>::result_type
+ typename result<as_expr(T const &)>::type
                 operator ()(T const &t) const
                 {
                     return typename Domain::template as_expr<T const>()(t);
@@ -647,14 +647,14 @@
 
                 #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
                 template<typename T, std::size_t N_>
- typename Domain::template as_expr<T[N_]>::result_type
+ typename result<as_expr(T (&)[N_])>::type
                 operator ()(T (&t)[N_]) const
                 {
                     return typename Domain::template as_expr<T[N_]>()(t);
                 }
 
                 template<typename T, std::size_t N_>
- typename Domain::template as_expr<T const[N_]>::result_type
+ typename result<as_expr(T const (&)[N_])>::type
                 operator ()(T const (&t)[N_]) const
                 {
                     return typename Domain::template as_expr<T const[N_]>()(t);
@@ -689,7 +689,7 @@
                 /// \param t The object to wrap.
                 /// \return <tt>proto::as_child\<Domain\>(t)</tt>
                 template<typename T>
- typename Domain::template as_child<T>::result_type
+ typename result<as_child(T &)>::type
                 operator ()(T &t) const
                 {
                     return typename Domain::template as_child<T>()(t);
@@ -698,7 +698,7 @@
                 /// \overload
                 ///
                 template<typename T>
- typename Domain::template as_child<T const>::result_type
+ typename result<as_child(T const &)>::type
                 operator ()(T const &t) const
                 {
                     return typename Domain::template as_child<T const>()(t);
@@ -923,7 +923,7 @@
         ///
         /// \param t The object to wrap.
         template<typename T>
- typename default_domain::as_expr<T>::result_type
+ typename result_of::as_expr<T, default_domain>::type
         as_expr(T &t BOOST_PROTO_DISABLE_IF_IS_CONST(T) BOOST_PROTO_DISABLE_IF_IS_FUNCTION(T))
         {
             return default_domain::as_expr<T>()(t);
@@ -932,7 +932,7 @@
         /// \overload
         ///
         template<typename T>
- typename default_domain::as_expr<T const>::result_type
+ typename result_of::as_expr<T const, default_domain>::type
         as_expr(T const &t)
         {
             return default_domain::as_expr<T const>()(t);
@@ -941,7 +941,7 @@
         /// \overload
         ///
         template<typename Domain, typename T>
- typename Domain::template as_expr<T>::result_type
+ typename result_of::as_expr<T, Domain>::type
         as_expr(T &t BOOST_PROTO_DISABLE_IF_IS_CONST(T) BOOST_PROTO_DISABLE_IF_IS_FUNCTION(T))
         {
             return typename Domain::template as_expr<T>()(t);
@@ -950,7 +950,7 @@
         /// \overload
         ///
         template<typename Domain, typename T>
- typename Domain::template as_expr<T const>::result_type
+ typename result_of::as_expr<T const, Domain>::type
         as_expr(T const &t)
         {
             return typename Domain::template as_expr<T const>()(t);
@@ -976,7 +976,7 @@
         ///
         /// \param t The object to wrap.
         template<typename T>
- typename default_domain::as_child<T>::result_type
+ typename result_of::as_child<T, default_domain>::type
         as_child(T &t BOOST_PROTO_DISABLE_IF_IS_CONST(T) BOOST_PROTO_DISABLE_IF_IS_FUNCTION(T))
         {
             return default_domain::as_child<T>()(t);
@@ -985,7 +985,7 @@
         /// \overload
         ///
         template<typename T>
- typename default_domain::as_child<T const>::result_type
+ typename result_of::as_child<T const, default_domain>::type
         as_child(T const &t)
         {
             return default_domain::as_child<T const>()(t);
@@ -994,7 +994,7 @@
         /// \overload
         ///
         template<typename Domain, typename T>
- typename Domain::template as_child<T>::result_type
+ typename result_of::as_child<T, Domain>::type
         as_child(T &t BOOST_PROTO_DISABLE_IF_IS_CONST(T) BOOST_PROTO_DISABLE_IF_IS_FUNCTION(T))
         {
             return typename Domain::template as_child<T>()(t);
@@ -1003,7 +1003,7 @@
         /// \overload
         ///
         template<typename Domain, typename T>
- typename Domain::template as_child<T const>::result_type
+ typename result_of::as_child<T const, Domain>::type
         as_child(T const &t)
         {
             return typename Domain::template as_child<T const>()(t);


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