Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-11-12 00:41:43


Author: eric_niebler
Date: 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
New Revision: 41022
URL: http://svn.boost.org/trac/boost/changeset/41022

Log:
port rest of examples
Added:
   branches/proto/v3/boost/xpressive/proto3/deep_copy.hpp (contents, props changed)
   branches/proto/v3/boost/xpressive/proto3/proto_typeof.hpp (contents, props changed)
Text files modified:
   branches/proto/v3/boost/xpressive/proto3/args.hpp | 2
   branches/proto/v3/boost/xpressive/proto3/expr.hpp | 41 ++++++++++++++++++++++++++++++++++++++++
   branches/proto/v3/boost/xpressive/proto3/make_expr.hpp | 2
   branches/proto/v3/boost/xpressive/proto3/proto.hpp | 3 +
   branches/proto/v3/boost/xpressive/proto3/transform/case.hpp | 6 +++++
   branches/proto/v3/libs/xpressive/proto3/example/vec3.cpp | 20 ++++++++----------
   branches/proto/v3/libs/xpressive/proto3/example/vector.cpp | 2
   7 files changed, 61 insertions(+), 15 deletions(-)

Modified: branches/proto/v3/boost/xpressive/proto3/args.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/args.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto3/args.hpp 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
@@ -145,7 +145,7 @@
             template<typename Ret, typename Fun, typename... Tail, typename... Head>
             static Ret call_(Fun const &fun, cons<Tail...> const &cons, Head const &...head)
             {
- call_<Ret>(fun, cons.cdr, head..., cons.car);
+ return call_<Ret>(fun, cons.cdr, head..., cons.car);
             }
 
             template<typename Ret, typename Fun, typename... Head>

Added: branches/proto/v3/boost/xpressive/proto3/deep_copy.hpp
==============================================================================
--- (empty file)
+++ branches/proto/v3/boost/xpressive/proto3/deep_copy.hpp 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
@@ -0,0 +1,124 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file deep_copy.hpp
+/// Replace all nodes stored by reference by nodes stored by value.
+//
+// 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_PROTO3_DEEP_COPY_HPP_EAN_11_21_2006
+#define BOOST_PROTO3_DEEP_COPY_HPP_EAN_11_21_2006
+
+#include <boost/xpressive/proto3/proto_fwd.hpp>
+#include <boost/xpressive/proto3/args.hpp>
+#include <boost/xpressive/proto3/expr.hpp>
+#include <boost/xpressive/proto3/traits.hpp>
+#include <boost/xpressive/proto3/generate.hpp>
+
+#define UNCV(X) \
+ typename remove_cv<X>::type
+
+#define UNREF(X) \
+ typename remove_reference<X>::type
+
+#define UNCVREF(X) \
+ UNCV(UNREF(X))
+
+namespace boost { namespace proto
+{
+ namespace detail
+ {
+ template<typename Expr, typename Args = typename Expr::proto_args>
+ struct deep_copy_impl;
+
+ struct deep_copy_cons
+ {
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename... Args>
+ struct result<This(Args...)>
+ {
+ typedef argsns_::cons<typename deep_copy_impl<UNCVREF(Args)>::type...> type;
+ };
+
+ template<typename... Args>
+ argsns_::cons<typename deep_copy_impl<UNCVREF(Args)>::type...>
+ operator()(Args const &... args) const
+ {
+ return argsns_::make_cons(deep_copy_impl<Args>::call(args)...);
+ }
+ };
+
+ template<typename Expr, typename T>
+ struct deep_copy_impl<Expr, term<T> >
+ {
+ typedef typename terminal<typename result_of::arg<Expr>::type>::type expr_type;
+ typedef typename Expr::proto_domain::template apply<expr_type>::type type;
+
+ static type call(Expr const &expr)
+ {
+ return Expr::proto_domain::make(expr_type::make(proto::arg(expr)));
+ }
+ };
+
+ template<typename Expr, typename... Args>
+ struct deep_copy_impl<Expr, args<Args...> >
+ {
+ typedef expr<typename Expr::proto_tag, args<
+ typename deep_copy_impl<UNCVREF(Args)>::type...
+ > > expr_type;
+ typedef typename Expr::proto_domain::template apply<expr_type>::type type;
+
+ static type call(Expr const &expr)
+ {
+ expr_type that = {
+ argsns_::fanout_args(
+ proto::detail::deep_copy_cons()
+ , expr.proto_base().proto_args_
+ )
+ };
+ return Expr::proto_domain::make(that);
+ }
+ };
+
+ }
+
+ namespace result_of
+ {
+ template<typename Expr>
+ struct deep_copy
+ : proto::detail::deep_copy_impl<Expr>
+ {};
+ }
+
+ namespace functional
+ {
+ struct deep_copy
+ {
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename Expr>
+ struct result<This(Expr)>
+ : result_of::deep_copy<UNCVREF(Expr)>
+ {};
+
+ template<typename Expr>
+ typename result_of::deep_copy<Expr>::type
+ operator()(Expr const &expr) const
+ {
+ return result_of::deep_copy<Expr>::call(expr);
+ }
+ };
+ }
+
+ functional::deep_copy const deep_copy = {};
+
+}}
+
+#undef UNCV
+#undef UNREF
+#undef UNCVREF
+
+#endif // BOOST_PROTO3_DEEP_COPY_HPP_EAN_11_21_2006

Modified: branches/proto/v3/boost/xpressive/proto3/expr.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/expr.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto3/expr.hpp 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
@@ -9,13 +9,40 @@
 #ifndef BOOST_PROTO3_EXPR_HPP_EAN_10_28_2007
 #define BOOST_PROTO3_EXPR_HPP_EAN_10_28_2007
 
+#include <cstddef>
+#include <boost/type_traits.hpp>
+#include <boost/utility/enable_if.hpp>
 #include <boost/xpressive/proto3/proto_fwd.hpp>
+#include <boost/xpressive/proto3/tags.hpp>
+#include <boost/xpressive/proto3/traits.hpp>
 
 namespace boost { namespace proto
 {
 
     namespace exprns_
     {
+ namespace detail
+ {
+ template<typename X, std::size_t N, typename Y>
+ void checked_copy(X (&x)[N], Y (&y)[N])
+ {
+ for(std::size_t i = 0; i < N; ++i)
+ {
+ y[i] = x[i];
+ }
+ }
+
+ 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>
+ {
+ typedef void type;
+ };
+ }
+
         template<typename Tag, typename Args, long Arity>
         struct expr
         {
@@ -49,6 +76,20 @@
                 return that;
             }
 
+ template<typename A, std::size_t N>
+ static expr make(
+ A (&a)[N]
+ , typename exprns_::detail::if_is_array<
+ typename Args::cons_type::car_type, N
+ >::type * = 0
+ )
+ {
+ typedef char arity_is_zero[0==Arity];
+ expr that;
+ exprns_::detail::checked_copy(a, that.proto_args_.car);
+ return that;
+ }
+
             expr &proto_base()
             {
                 return *this;

Modified: branches/proto/v3/boost/xpressive/proto3/make_expr.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/make_expr.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto3/make_expr.hpp 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
@@ -407,7 +407,7 @@
 
             static type const call(reference a)
             {
- expr_type that = {a};
+ expr_type that = {{a}};
                 return Domain::make(that);
             }
         };

Modified: branches/proto/v3/boost/xpressive/proto3/proto.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/proto.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto3/proto.hpp 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
@@ -17,11 +17,12 @@
 #include <boost/xpressive/proto3/debug.hpp>
 #include <boost/xpressive/proto3/traits.hpp>
 #include <boost/xpressive/proto3/domain.hpp>
+#include <boost/xpressive/proto3/matches.hpp>
 #include <boost/xpressive/proto3/extends.hpp>
 #include <boost/xpressive/proto3/literal.hpp>
 #include <boost/xpressive/proto3/generate.hpp>
 #include <boost/xpressive/proto3/operators.hpp>
-#include <boost/xpressive/proto3/matches.hpp>
+#include <boost/xpressive/proto3/deep_copy.hpp>
 #include <boost/xpressive/proto3/transform.hpp>
 #include <boost/xpressive/proto3/fusion.hpp>
 #include <boost/xpressive/proto3/make_expr.hpp>

Added: branches/proto/v3/boost/xpressive/proto3/proto_typeof.hpp
==============================================================================
--- (empty file)
+++ branches/proto/v3/boost/xpressive/proto3/proto_typeof.hpp 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
@@ -0,0 +1,94 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file proto_typeof.hpp
+/// Type registrations so that proto expression templates can be used together
+/// with the Boost.Typeof library.
+//
+// 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_PROTO3_PROTO_TYPEOF_H
+#define BOOST_PROTO3_PROTO_TYPEOF_H
+
+#include <boost/config.hpp>
+#include <boost/typeof/typeof.hpp>
+#include <boost/xpressive/proto3/proto_fwd.hpp>
+#include <boost/xpressive/proto3/deep_copy.hpp>
+#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
+
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::terminal)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::posit)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::negate)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::dereference)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::complement)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::address_of)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::logical_not)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::pre_inc)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::pre_dec)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::post_inc)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::post_dec)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::shift_left)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::shift_right)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::multiplies)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::divides)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::modulus)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::plus)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::minus)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::less)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::greater)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::less_equal)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::greater_equal)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::equal_to)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::not_equal_to)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::logical_or)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::logical_and)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::bitwise_and)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::bitwise_or)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::bitwise_xor)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::comma)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::mem_ptr)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::shift_left_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::shift_right_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::multiplies_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::divides_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::modulus_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::plus_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::minus_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::bitwise_and_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::bitwise_or_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::bitwise_xor_assign)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::subscript)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::if_else_)
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::tag::function)
+
+BOOST_TYPEOF_REGISTER_TYPE(boost::proto::exprns_::is_proto_expr)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::exprns_::expr, (typename)(typename)(long))
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::utility::literal, (typename)(typename))
+
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::term, 1)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 1)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 2)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 3)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 4)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 5)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 6)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 7)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 8)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 9)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 10)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 11)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 12)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 13)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 14)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 15)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 16)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 17)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 18)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 19)
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::proto::argsns_::args, 20)
+
+#define BOOST_PROTO_AUTO(Var, Expr) BOOST_AUTO(Var, boost::proto::deep_copy(Expr))
+#define BOOST_PROTO_AUTO_TPL(Var, Expr) BOOST_AUTO_TPL(Var, boost::proto::deep_copy(Expr))
+
+#endif

Modified: branches/proto/v3/boost/xpressive/proto3/transform/case.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/transform/case.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto3/transform/case.hpp 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
@@ -127,6 +127,12 @@
                 return Type(args...);
             }
 
+ template<typename Type>
+ Type construct_()
+ {
+ return Type();
+ }
+
             template<
                 typename Expr
               , typename State

Modified: branches/proto/v3/libs/xpressive/proto3/example/vec3.cpp
==============================================================================
--- branches/proto/v3/libs/xpressive/proto3/example/vec3.cpp (original)
+++ branches/proto/v3/libs/xpressive/proto3/example/vec3.cpp 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
@@ -16,11 +16,9 @@
 #include <boost/xpressive/proto3/proto.hpp>
 #include <boost/xpressive/proto3/context.hpp>
 #include <boost/xpressive/proto3/proto_typeof.hpp>
-#include <boost/xpressive/proto3/transform/arg.hpp>
-#include <boost/xpressive/proto3/transform/fold.hpp>
-#include <boost/xpressive/proto3/transform/apply.hpp>
-#include <boost/xpressive/proto3/transform/function.hpp>
+#include <boost/xpressive/proto3/transform.hpp>
 using namespace boost::proto;
+using namespace transform;
 namespace mpl = boost::mpl;
 
 // Here is an evaluation context that indexes into a Vec3
@@ -63,23 +61,23 @@
       int count;
 };
 
+struct one : mpl::int_<1> {};
+struct iplus : std::plus<int>, function_transform {};
+
 // Here is a transform that does the same thing as the above context.
 // It demonstrates the use of the std::plus<> function object
-// with the function2 transform. With minor modifications, this
+// with the fold transform. With minor modifications, this
 // transform could be used to calculate the leaf count at compile
 // time, rather at runtime.
 struct CountLeaves
   : or_<
         // match a Vec3 terminal, return 1
- transform::always<terminal<int[3]>, mpl::int_<1> >
+ case_<terminal<int[3]>, one() >
         // match a terminal, return int() (which is 0)
- , transform::always<terminal<_>, int>
+ , case_<terminal<_>, int() >
         // fold everything else, using std::plus<> to add
         // the leaf count of each child to the accumulated state.
- , transform::fold<
- nary_expr<_, vararg<transform::function2<CountLeaves, std::plus<int> > > >
- , int // initial state of the fold is int() (which is 0)
- >
+ , case_< nary_expr<_, vararg<_> >, fold<_, int(), iplus(CountLeaves, _state) > >
>
 {};
 

Modified: branches/proto/v3/libs/xpressive/proto3/example/vector.cpp
==============================================================================
--- branches/proto/v3/libs/xpressive/proto3/example/vector.cpp (original)
+++ branches/proto/v3/libs/xpressive/proto3/example/vector.cpp 2007-11-12 00:41:39 EST (Mon, 12 Nov 2007)
@@ -77,7 +77,7 @@
         {
             if(ctx.size_ != proto::arg(expr).size())
             {
- throw std::invalid_argument("LHS and RHS are not compatible");
+ throw std::runtime_error("LHS and RHS are not compatible");
             }
         }
     };


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