Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53567 - in trunk/boost/proto: . context transform
From: eric_at_[hidden]
Date: 2009-06-02 03:26:51


Author: eric_niebler
Date: 2009-06-02 03:26:49 EDT (Tue, 02 Jun 2009)
New Revision: 53567
URL: http://svn.boost.org/trac/boost/changeset/53567

Log:
misc clean-up and compile time tweaks
Text files modified:
   trunk/boost/proto/context/callable.hpp | 3 +
   trunk/boost/proto/expr.hpp | 73 +++++++++++++++++++--------------------
   trunk/boost/proto/generate.hpp | 10 +++++
   trunk/boost/proto/transform/impl.hpp | 65 ++++++++++++++++++-----------------
   trunk/boost/proto/transform/make.hpp | 12 ++++--
   5 files changed, 89 insertions(+), 74 deletions(-)

Modified: trunk/boost/proto/context/callable.hpp
==============================================================================
--- trunk/boost/proto/context/callable.hpp (original)
+++ trunk/boost/proto/context/callable.hpp 2009-06-02 03:26:49 EDT (Tue, 02 Jun 2009)
@@ -258,6 +258,9 @@
                         )
                     );
                 operator fun_type *() const;
+
+ private:
+ callable_context_wrapper &operator =(callable_context_wrapper const &);
             };
 
             template<typename Expr, typename Context>

Modified: trunk/boost/proto/expr.hpp
==============================================================================
--- trunk/boost/proto/expr.hpp (original)
+++ trunk/boost/proto/expr.hpp 2009-06-02 03:26:49 EDT (Tue, 02 Jun 2009)
@@ -72,24 +72,34 @@
                 typedef Expr *type;
             };
 
- template<typename X, std::size_t N, typename Y>
- void checked_copy(X (&x)[N], Y (&y)[N])
+ template<typename T, typename Tag, typename Arg0>
+ proto::expr<Tag, proto::term<Arg0>, 0> make_terminal(T &t, proto::expr<Tag, proto::term<Arg0>, 0> *)
             {
+ proto::expr<Tag, proto::term<Arg0>, 0> that = {t};
+ return that;
+ }
+
+ template<typename T, typename Tag, typename Arg0, std::size_t N>
+ proto::expr<Tag, proto::term<Arg0[N]>, 0> make_terminal(T (&t)[N], proto::expr<Tag, proto::term<Arg0[N]>, 0> *)
+ {
+ expr<Tag, proto::term<Arg0[N]>, 0> that;
                 for(std::size_t i = 0; i < N; ++i)
                 {
- y[i] = x[i];
+ that.child0[i] = t[i];
                 }
+ return that;
             }
 
- template<typename T, std::size_t N>
- struct if_is_array
- {};
-
- template<typename T, std::size_t N>
- struct if_is_array<T[N], N>
+ template<typename T, typename Tag, typename Arg0, std::size_t N>
+ proto::expr<Tag, proto::term<Arg0[N]>, 0> make_terminal(T const(&t)[N], proto::expr<Tag, proto::term<Arg0[N]>, 0> *)
             {
- typedef int type;
- };
+ expr<Tag, proto::term<Arg0[N]>, 0> that;
+ for(std::size_t i = 0; i < N; ++i)
+ {
+ that.child0[i] = t[i];
+ }
+ return that;
+ }
 
         }
 
@@ -111,6 +121,9 @@
         // expr<> because uses of proto_base_expr in proto::matches<> shouldn't
         // case the expr<> type to be instantiated. (<-- Check that assumtion!)
         // OR, should expr<>::proto_base_expr be a typedef for basic_expr<>?
+ // It should, and proto_base() can return *this reinterpret_cast to
+ // a basic_expr because they should be layout compatible. Or not, because
+ // that would incur an extra template instantiation. :-(
 
         BOOST_PROTO_BEGIN_ADL_NAMESPACE(exprns_)
         #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PROTO_MAX_ARITY, <boost/proto/expr.hpp>))
@@ -179,10 +192,6 @@
         ///
         /// \c proto::expr\<\> is a valid Fusion random-access sequence, where
         /// the elements of the sequence are the child expressions.
-
- //template<typename Tag, typename Args>
- //struct expr<Tag, Args, BOOST_PP_ITERATION() >
-
         #if IS_TERMINAL
         template<typename Tag, typename Arg0>
         struct expr<Tag, term<Arg0>, 0>
@@ -222,43 +231,31 @@
                 return *this;
             }
 
+ #if IS_TERMINAL
             /// \return A new \c expr\<\> object initialized with the specified
             /// arguments.
             ///
- template<BOOST_PP_ENUM_PARAMS(ARG_COUNT, typename A)>
- static expr const make(BOOST_PP_ENUM_BINARY_PARAMS(ARG_COUNT, A, const &a))
- {
- expr that = {BOOST_PP_ENUM_PARAMS(ARG_COUNT, a)};
- return that;
- }
-
- #if IS_TERMINAL
- /// \overload
- ///
             template<typename A0>
             static expr const make(A0 &a0)
             {
- expr that = {a0};
- return that;
+ return detail::make_terminal(a0, static_cast<expr *>(0));
             }
 
             /// \overload
             ///
- template<typename A0, std::size_t N>
- static expr const make(A0 (&a0)[N], typename detail::if_is_array<proto_child0, N>::type = 0)
+ template<typename A0>
+ static expr const make(A0 const &a0)
             {
- expr that;
- detail::checked_copy(a0, that.child0);
- return that;
+ return detail::make_terminal(a0, static_cast<expr *>(0));
             }
-
- /// \overload
+ #else
+ /// \return A new \c expr\<\> object initialized with the specified
+ /// arguments.
             ///
- template<typename A0, std::size_t N>
- static expr const make(A0 const (&a0)[N], typename detail::if_is_array<proto_child0, N>::type = 0)
+ template<BOOST_PP_ENUM_PARAMS(ARG_COUNT, typename A)>
+ static expr const make(BOOST_PP_ENUM_BINARY_PARAMS(ARG_COUNT, A, const &a))
             {
- expr that;
- detail::checked_copy(a0, that.child0);
+ expr that = {BOOST_PP_ENUM_PARAMS(ARG_COUNT, a)};
                 return that;
             }
         #endif

Modified: trunk/boost/proto/generate.hpp
==============================================================================
--- trunk/boost/proto/generate.hpp (original)
+++ trunk/boost/proto/generate.hpp 2009-06-02 03:26:49 EDT (Tue, 02 Jun 2009)
@@ -344,6 +344,16 @@
 
     }}
 
+ // Specialization of boost::result_of to eliminate some unnecessary template instantiations
+ namespace boost
+ {
+ template<typename Expr>
+ struct result_of<proto::default_domain(Expr)>
+ {
+ typedef Expr type;
+ };
+ }
+
     #endif // BOOST_PROTO_GENERATE_HPP_EAN_02_13_2007
 
 #else // BOOST_PP_IS_ITERATING

Modified: trunk/boost/proto/transform/impl.hpp
==============================================================================
--- trunk/boost/proto/transform/impl.hpp (original)
+++ trunk/boost/proto/transform/impl.hpp 2009-06-02 03:26:49 EDT (Tue, 02 Jun 2009)
@@ -15,11 +15,6 @@
 
 namespace boost { namespace proto
 {
- template<typename PrimitiveTransform, typename Expr, typename State = int, typename Data = int>
- struct apply_transform
- : PrimitiveTransform::template impl<Expr, State, Data>
- {};
-
     struct transform_base
     {
         BOOST_PROTO_CALLABLE()
@@ -29,6 +24,27 @@
     struct empty_base
     {};
 
+ namespace detail
+ {
+ template<typename Sig>
+ struct apply_transform;
+
+ template<typename PrimitiveTransform, typename Expr>
+ struct apply_transform<PrimitiveTransform(Expr)>
+ : PrimitiveTransform::template impl<Expr, int, int>
+ {};
+
+ template<typename PrimitiveTransform, typename Expr, typename State>
+ struct apply_transform<PrimitiveTransform(Expr, State)>
+ : PrimitiveTransform::template impl<Expr, State, int>
+ {};
+
+ template<typename PrimitiveTransform, typename Expr, typename State, typename Data>
+ struct apply_transform<PrimitiveTransform(Expr, State, Data)>
+ : PrimitiveTransform::template impl<Expr, State, Data>
+ {};
+ }
+
     template<
         typename PrimitiveTransform
       , typename Base BOOST_PROTO_WHEN_BUILDING_DOCS(= transform_base)
@@ -38,62 +54,47 @@
         typedef PrimitiveTransform transform_type;
 
         template<typename Sig>
- struct result;
-
- template<typename This, typename Expr>
- struct result<This(Expr)>
- {
- typedef typename PrimitiveTransform::template impl<Expr, int, int>::result_type type;
- };
-
- template<typename This, typename Expr, typename State>
- struct result<This(Expr, State)>
- {
- typedef typename PrimitiveTransform::template impl<Expr, State, int>::result_type type;
- };
-
- template<typename This, typename Expr, typename State, typename Data>
- struct result<This(Expr, State, Data)>
+ struct result
         {
- typedef typename PrimitiveTransform::template impl<Expr, State, Data>::result_type type;
+ typedef typename detail::apply_transform<Sig>::result_type type;
         };
 
         template<typename Expr>
- typename apply_transform<PrimitiveTransform, Expr &>::result_type
+ typename detail::apply_transform<PrimitiveTransform(Expr &)>::result_type
         operator ()(Expr &e) const
         {
             int i = 0;
- return apply_transform<PrimitiveTransform, Expr &>()(e, i, i);
+ return detail::apply_transform<PrimitiveTransform(Expr &)>()(e, i, i);
         }
 
         template<typename Expr, typename State>
- typename apply_transform<PrimitiveTransform, Expr &, State &>::result_type
+ typename detail::apply_transform<PrimitiveTransform(Expr &, State &)>::result_type
         operator ()(Expr &e, State &s) const
         {
             int i = 0;
- return apply_transform<PrimitiveTransform, Expr &, State &>()(e, s, i);
+ return detail::apply_transform<PrimitiveTransform(Expr &, State &)>()(e, s, i);
         }
 
         template<typename Expr, typename State>
- typename apply_transform<PrimitiveTransform, Expr &, State const &>::result_type
+ typename detail::apply_transform<PrimitiveTransform(Expr &, State const &)>::result_type
         operator ()(Expr &e, State const &s) const
         {
             int i = 0;
- return apply_transform<PrimitiveTransform, Expr &, State const &>()(e, s, i);
+ return detail::apply_transform<PrimitiveTransform(Expr &, State const &)>()(e, s, i);
         }
 
         template<typename Expr, typename State, typename Data>
- typename apply_transform<PrimitiveTransform, Expr &, State &, Data &>::result_type
+ typename detail::apply_transform<PrimitiveTransform(Expr &, State &, Data &)>::result_type
         operator ()(Expr &e, State &s, Data &d) const
         {
- return apply_transform<PrimitiveTransform, Expr &, State &, Data &>()(e, s, d);
+ return detail::apply_transform<PrimitiveTransform(Expr &, State &, Data &)>()(e, s, d);
         }
 
         template<typename Expr, typename State, typename Data>
- typename apply_transform<PrimitiveTransform, Expr &, State const &, Data &>::result_type
+ typename detail::apply_transform<PrimitiveTransform(Expr &, State const &, Data &)>::result_type
         operator ()(Expr &e, State const &s, Data &d) const
         {
- return apply_transform<PrimitiveTransform, Expr &, State const &, Data &>()(e, s, d);
+ return detail::apply_transform<PrimitiveTransform(Expr &, State const &, Data &)>()(e, s, d);
         }
     };
 

Modified: trunk/boost/proto/transform/make.hpp
==============================================================================
--- trunk/boost/proto/transform/make.hpp (original)
+++ trunk/boost/proto/transform/make.hpp 2009-06-02 03:26:49 EDT (Tue, 02 Jun 2009)
@@ -65,7 +65,9 @@
             {};
 
             template<typename R, typename Expr, typename State, typename Data
- , bool IsTransform = is_callable<R>::value
+ // BUGBUG this should be is_transform, but if R is a template instantiation
+ // it will cause the template to be instantiated, whereas is_callable will not.
+ , bool IsTransform = is_callable<R>::value
>
             struct make_if_;
 
@@ -96,9 +98,11 @@
             // TODO could optimize this if R is a transform
             template<typename R, typename Expr, typename State, typename Data>
             struct make_if_<R, Expr, State, Data, true>
- : remove_const<typename remove_reference<
- typename boost::result_of<R(Expr, State, Data)>::type
- >::type>
+ : remove_const<
+ typename remove_reference<
+ typename R::template impl<Expr, State, Data>::result_type
+ >::type
+ >
             {};
 
             template<typename Type, bool IsAggregate = is_aggregate<Type>::value>


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