Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80262 - in trunk: boost/proto/transform libs/proto/test
From: eric_at_[hidden]
Date: 2012-08-27 14:14:21


Author: eric_niebler
Date: 2012-08-27 14:14:20 EDT (Mon, 27 Aug 2012)
New Revision: 80262
URL: http://svn.boost.org/trac/boost/changeset/80262

Log:
bite the bullet and add overloads to proto::transform that accept const-ref expressions
Added:
   trunk/libs/proto/test/cpp-next_bug.cpp (contents, props changed)
Text files modified:
   trunk/boost/proto/transform/impl.hpp | 44 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/proto/test/Jamfile.v2 | 1
   2 files changed, 45 insertions(+), 0 deletions(-)

Modified: trunk/boost/proto/transform/impl.hpp
==============================================================================
--- trunk/boost/proto/transform/impl.hpp (original)
+++ trunk/boost/proto/transform/impl.hpp 2012-08-27 14:14:20 EDT (Mon, 27 Aug 2012)
@@ -100,6 +100,16 @@
         return boost::proto::detail::apply_transform<transform_type(Expr &)>()(e, s, d); \
     } \
                                                                                                                 \
+ template<typename Expr> \
+ BOOST_FORCEINLINE \
+ typename boost::proto::detail::apply_transform<transform_type(Expr const &)>::result_type \
+ operator ()(Expr const &e) const \
+ { \
+ boost::proto::empty_state s = 0; \
+ boost::proto::empty_env d; \
+ return boost::proto::detail::apply_transform<transform_type(Expr const &)>()(e, s, d); \
+ } \
+ \
     template<typename Expr, typename State> \
     BOOST_FORCEINLINE \
     typename boost::proto::detail::apply_transform<transform_type(Expr &, State &)>::result_type \
@@ -111,6 +121,15 @@
                                                                                                                 \
     template<typename Expr, typename State> \
     BOOST_FORCEINLINE \
+ typename boost::proto::detail::apply_transform<transform_type(Expr const &, State &)>::result_type \
+ operator ()(Expr const &e, State &s) const \
+ { \
+ boost::proto::empty_env d; \
+ return boost::proto::detail::apply_transform<transform_type(Expr const &, State &)>()(e, s, d); \
+ } \
+ \
+ template<typename Expr, typename State> \
+ BOOST_FORCEINLINE \
     typename boost::proto::detail::apply_transform<transform_type(Expr &, State const &)>::result_type \
     operator ()(Expr &e, State const &s) const \
     { \
@@ -118,6 +137,15 @@
         return boost::proto::detail::apply_transform<transform_type(Expr &, State const &)>()(e, s, d); \
     } \
                                                                                                                 \
+ template<typename Expr, typename State> \
+ BOOST_FORCEINLINE \
+ typename boost::proto::detail::apply_transform<transform_type(Expr const &, State const &)>::result_type \
+ operator ()(Expr const &e, State const &s) const \
+ { \
+ boost::proto::empty_env d; \
+ return boost::proto::detail::apply_transform<transform_type(Expr const &, State const &)>()(e, s, d); \
+ } \
+ \
     template<typename Expr, typename State, typename Data> \
     BOOST_FORCEINLINE \
     typename boost::proto::detail::apply_transform<transform_type(Expr &, State &, Data &)>::result_type \
@@ -128,11 +156,27 @@
                                                                                                                 \
     template<typename Expr, typename State, typename Data> \
     BOOST_FORCEINLINE \
+ typename boost::proto::detail::apply_transform<transform_type(Expr const &, State &, Data &)>::result_type \
+ operator ()(Expr const &e, State &s, Data &d) const \
+ { \
+ return boost::proto::detail::apply_transform<transform_type(Expr const &, State &, Data &)>()(e, s, d); \
+ } \
+ \
+ template<typename Expr, typename State, typename Data> \
+ BOOST_FORCEINLINE \
     typename boost::proto::detail::apply_transform<transform_type(Expr &, State const &, Data &)>::result_type \
     operator ()(Expr &e, State const &s, Data &d) const \
     { \
         return boost::proto::detail::apply_transform<transform_type(Expr &, State const &, Data &)>()(e, s, d); \
     } \
+ \
+ template<typename Expr, typename State, typename Data> \
+ BOOST_FORCEINLINE \
+ typename boost::proto::detail::apply_transform<transform_type(Expr const &, State const &, Data &)>::result_type \
+ operator ()(Expr const &e, State const &s, Data &d) const \
+ { \
+ return boost::proto::detail::apply_transform<transform_type(Expr const &, State const &, Data &)>()(e, s, d); \
+ } \
     /**/
 
 #else

Modified: trunk/libs/proto/test/Jamfile.v2
==============================================================================
--- trunk/libs/proto/test/Jamfile.v2 (original)
+++ trunk/libs/proto/test/Jamfile.v2 2012-08-27 14:14:20 EDT (Mon, 27 Aug 2012)
@@ -23,6 +23,7 @@
     :
         [ run calculator.cpp ]
         [ run constrained_ops.cpp ]
+ [ run cpp-next_bug.cpp ]
         [ run deep_copy.cpp ]
         [ run display_expr.cpp ]
         [ run deduce_domain.cpp ]

Added: trunk/libs/proto/test/cpp-next_bug.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/proto/test/cpp-next_bug.cpp 2012-08-27 14:14:20 EDT (Mon, 27 Aug 2012)
@@ -0,0 +1,80 @@
+///////////////////////////////////////////////////////////////////////////////
+// cpp-next_bug.hpp
+//
+// Copyright 2012 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)
+
+#include <vector>
+#include <boost/proto/proto.hpp>
+#include <boost/test/unit_test.hpp>
+namespace mpl = boost::mpl;
+namespace proto = boost::proto;
+using proto::_;
+
+namespace linear_algebra
+{
+ // A trait that returns true only for std::vector
+ template<typename T>
+ struct is_std_vector
+ : mpl::false_
+ {};
+
+ template<typename T, typename A>
+ struct is_std_vector<std::vector<T, A> >
+ : mpl::true_
+ {};
+
+ // A type used as a domain for linear algebra expressions
+ struct linear_algebra_domain
+ : proto::domain<>
+ {};
+
+ // Define all the operator overloads for combining std::vectors
+ BOOST_PROTO_DEFINE_OPERATORS(is_std_vector, linear_algebra_domain)
+
+ // Take any expression and turn each node
+ // into a subscript expression, using the
+ // state as the RHS.
+ struct Distribute
+ : proto::or_<
+ proto::when<proto::terminal<_>, proto::_make_subscript(_, proto::_state)>
+ , proto::plus<Distribute, Distribute>
+ >
+ {};
+
+ struct Optimize
+ : proto::or_<
+ proto::when<
+ proto::subscript<Distribute, proto::terminal<_> >,
+ Distribute(proto::_left, proto::_right)
+ >
+ , proto::plus<Optimize, Optimize>
+ , proto::terminal<_>
+ >
+ {};
+}
+
+static const int celems = 4;
+static int const value[celems] = {1,2,3,4};
+std::vector<int> A(value, value+celems), B(A);
+
+void test1()
+{
+ using namespace linear_algebra;
+ proto::_default<> eval;
+ BOOST_CHECK_EQUAL(8, eval(Optimize()((A + B)[3])));
+}
+
+using namespace boost::unit_test;
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("test deducing domains from sub-domains");
+
+ test->add(BOOST_TEST_CASE(&test1));
+
+ return test;
+}


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