Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68369 - in sandbox/SOC/2010/phoenix3: boost/phoenix/core libs/phoenix/test libs/phoenix/test/boost_bind_compatibility
From: thom.heller_at_[hidden]
Date: 2011-01-22 13:23:34


Author: theller
Date: 2011-01-22 13:23:32 EST (Sat, 22 Jan 2011)
New Revision: 68369
URL: http://svn.boost.org/trac/boost/changeset/68369

Log:
made phoenix actor Assignable
Added:
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/bug4853.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp | 63 +++++++++++++++++++++++++++++++++++++++
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_and_or_test.cpp | 26 ++++++++--------
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_const_test.cpp | 46 ++++++++++++++--------------
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_not_test.cpp | 10 +++---
   4 files changed, 103 insertions(+), 42 deletions(-)

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp 2011-01-22 13:23:32 EST (Sat, 22 Jan 2011)
@@ -21,6 +21,7 @@
 #include <boost/proto/extends.hpp>
 #include <boost/utility/result_of.hpp>
 #include <boost/mpl/void.hpp>
+#include <cstring>
 
 namespace boost { namespace phoenix
 {
@@ -40,6 +41,54 @@
             template <typename T>
             error_invalid_lambda_expr(T const&) {}
         };
+
+ struct do_assign
+ {
+ BOOST_PROTO_CALLABLE()
+
+ typedef void result_type;
+
+ template <typename T1, typename T2>
+ void operator()(T1 & t1, T2 const & t2) const
+ {
+ proto::value(t1) = proto::value(t2);
+ }
+ };
+
+
+ #define PHOENIX_ACTOR_ASSIGN_CHILD(Z, N, D) \
+ assign(proto::_child_c<N>, proto::_child_c<N>(proto::_state)) \
+ /**/
+ #define PHOENIX_ACTOR_ASSIGN_CALL(Z, N, D) \
+ proto::when< \
+ proto::nary_expr<proto::_ , \
+ BOOST_PP_ENUM_PARAMS(N, proto::_ BOOST_PP_INTERCEPT) \
+ > \
+ , proto::and_< \
+ BOOST_PP_ENUM( \
+ N \
+ , PHOENIX_ACTOR_ASSIGN_CHILD \
+ , _ \
+ ) \
+ > \
+ > \
+ /**/
+
+ struct assign
+ : proto::or_<
+ BOOST_PP_ENUM_SHIFTED(
+ PHOENIX_LIMIT
+ , PHOENIX_ACTOR_ASSIGN_CALL
+ , _
+ )
+ , proto::when<
+ proto::terminal<proto::_>
+ , do_assign(proto::_, proto::_state)
+ >
+ >
+ {};
+ #undef PHOENIX_ACTOR_ASSIGN_CALL
+ #undef PHOENIX_ACTOR_ASSIGN_CHILD
     }
 
     // Bring in the result_of::actor<>
@@ -58,7 +107,19 @@
     struct actor
     {
         BOOST_PROTO_BASIC_EXTENDS(Expr, actor<Expr>, phoenix_domain)
- BOOST_PROTO_EXTENDS_ASSIGN()
+
+ // providing operator= to be assignable
+ actor& operator=(actor const& other)
+ {
+ detail::assign()(*this, other);
+ return *this;
+ }
+ actor& operator=(actor & other)
+ {
+ detail::assign()(*this, other);
+ return *this;
+ }
+ BOOST_PROTO_EXTENDS_ASSIGN_()
         BOOST_PROTO_EXTENDS_SUBSCRIPT()
 
         template <typename Sig>

Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_and_or_test.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_and_or_test.cpp (original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_and_or_test.cpp 2011-01-22 13:23:32 EST (Sat, 22 Jan 2011)
@@ -35,7 +35,7 @@
 
 template <typename F, typename A1, typename A2, typename R>
 void
-test(F f, A1 a1, A2 a2, R r)
+tester(F f, A1 a1, A2 a2, R r)
 {
     BOOST_TEST(f(a1, a2) == r);
 }
@@ -48,27 +48,27 @@
 
     // &&
 
- test(bind(f, true) && bind(g, true), false, false, f(true) && g(true));
- test(bind(f, true) && bind(g, false), false, false, f(true) && g(false));
+ tester(bind(f, true) && bind(g, true), false, false, f(true) && g(true));
+ tester(bind(f, true) && bind(g, false), false, false, f(true) && g(false));
 
- test(bind(f, false) && bind(h), false, false, f(false) && h());
+ tester(bind(f, false) && bind(h), false, false, f(false) && h());
 
- test(bind(f, _1) && bind(g, _2), true, true, f(true) && g(true));
- test(bind(f, _1) && bind(g, _2), true, false, f(true) && g(false));
+ tester(bind(f, _1) && bind(g, _2), true, true, f(true) && g(true));
+ tester(bind(f, _1) && bind(g, _2), true, false, f(true) && g(false));
 
- test(bind(f, _1) && bind(h), false, false, f(false) && h());
+ tester(bind(f, _1) && bind(h), false, false, f(false) && h());
 
     // ||
 
- test(bind(f, false) || bind(g, true), false, false, f(false) || g(true));
- test(bind(f, false) || bind(g, false), false, false, f(false) || g(false));
+ tester(bind(f, false) || bind(g, true), false, false, f(false) || g(true));
+ tester(bind(f, false) || bind(g, false), false, false, f(false) || g(false));
 
- test(bind(f, true) || bind(h), false, false, f(true) || h());
+ tester(bind(f, true) || bind(h), false, false, f(true) || h());
 
- test(bind(f, _1) || bind(g, _2), false, true, f(false) || g(true));
- test(bind(f, _1) || bind(g, _2), false, false, f(false) || g(false));
+ tester(bind(f, _1) || bind(g, _2), false, true, f(false) || g(true));
+ tester(bind(f, _1) || bind(g, _2), false, false, f(false) || g(false));
 
- test(bind(f, _1) || (h), true, false, f(true) || h());
+ tester(bind(f, _1) || (h), true, false, f(true) || h());
 
     //
 

Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_const_test.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_const_test.cpp (original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_const_test.cpp 2011-01-22 13:23:32 EST (Sat, 22 Jan 2011)
@@ -136,12 +136,12 @@
     global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
 }
 
-template<class F, class A> long test(F const & f, A const & a)
+template<class F, class A> long tester(F const & f, A const & a)
 {
     return f(a);
 }
 
-template<class F, class A> long testv(F const & f, A const & a)
+template<class F, class A> long testerv(F const & f, A const & a)
 {
     f(a);
     return global_result;
@@ -154,27 +154,27 @@
 
     int const i = 1;
 
- BOOST_TEST( test( bind(f_0), i ) == 17041L );
- BOOST_TEST( test( bind(f_1, _1), i ) == 1L );
- BOOST_TEST( test( bind(f_2, _1, 2), i ) == 21L );
- BOOST_TEST( test( bind(f_3, _1, 2, 3), i ) == 321L );
- BOOST_TEST( test( bind(f_4, _1, 2, 3, 4), i ) == 4321L );
- BOOST_TEST( test( bind(f_5, _1, 2, 3, 4, 5), i ) == 54321L );
- BOOST_TEST( test( bind(f_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
- BOOST_TEST( test( bind(f_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
- BOOST_TEST( test( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
- BOOST_TEST( test( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
-
- BOOST_TEST( testv( bind(fv_0), i ) == 17041L );
- BOOST_TEST( testv( bind(fv_1, _1), i ) == 1L );
- BOOST_TEST( testv( bind(fv_2, _1, 2), i ) == 21L );
- BOOST_TEST( testv( bind(fv_3, _1, 2, 3), i ) == 321L );
- BOOST_TEST( testv( bind(fv_4, _1, 2, 3, 4), i ) == 4321L );
- BOOST_TEST( testv( bind(fv_5, _1, 2, 3, 4, 5), i ) == 54321L );
- BOOST_TEST( testv( bind(fv_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
- BOOST_TEST( testv( bind(fv_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
- BOOST_TEST( testv( bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
- BOOST_TEST( testv( bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
+ BOOST_TEST( tester( bind(f_0), i ) == 17041L );
+ BOOST_TEST( tester( bind(f_1, _1), i ) == 1L );
+ BOOST_TEST( tester( bind(f_2, _1, 2), i ) == 21L );
+ BOOST_TEST( tester( bind(f_3, _1, 2, 3), i ) == 321L );
+ BOOST_TEST( tester( bind(f_4, _1, 2, 3, 4), i ) == 4321L );
+ BOOST_TEST( tester( bind(f_5, _1, 2, 3, 4, 5), i ) == 54321L );
+ BOOST_TEST( tester( bind(f_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
+ BOOST_TEST( tester( bind(f_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
+ BOOST_TEST( tester( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
+ BOOST_TEST( tester( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
+
+ BOOST_TEST( testerv( bind(fv_0), i ) == 17041L );
+ BOOST_TEST( testerv( bind(fv_1, _1), i ) == 1L );
+ BOOST_TEST( testerv( bind(fv_2, _1, 2), i ) == 21L );
+ BOOST_TEST( testerv( bind(fv_3, _1, 2, 3), i ) == 321L );
+ BOOST_TEST( testerv( bind(fv_4, _1, 2, 3, 4), i ) == 4321L );
+ BOOST_TEST( testerv( bind(fv_5, _1, 2, 3, 4, 5), i ) == 54321L );
+ BOOST_TEST( testerv( bind(fv_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
+ BOOST_TEST( testerv( bind(fv_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
+ BOOST_TEST( testerv( bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
+ BOOST_TEST( testerv( bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
 }
 
 int main()

Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_not_test.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_not_test.cpp (original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/boost_bind_compatibility/bind_not_test.cpp 2011-01-22 13:23:32 EST (Sat, 22 Jan 2011)
@@ -32,7 +32,7 @@
 
 #include <boost/detail/lightweight_test.hpp>
 
-template<class F, class A1, class R> void test( F f, A1 a1, R r )
+template<class F, class A1, class R> void tester( F f, A1 a1, R r )
 {
     BOOST_TEST( f(a1) == r );
 }
@@ -52,10 +52,10 @@
     using boost::phoenix::bind;
     using boost::phoenix::placeholders::_1;
 
- test( !bind( f, true ), 0, !f( true ) );
- test( !bind( g, _1 ), 5, !g( 5 ) );
- test( bind( f, !bind( f, true ) ), 0, f( !f( true ) ) );
- test( bind( f, !bind( f, _1 ) ), true, f( !f( true ) ) );
+ tester( !bind( f, true ), 0, !f( true ) );
+ tester( !bind( g, _1 ), 5, !g( 5 ) );
+ tester( bind( f, !bind( f, true ) ), 0, f( !f( true ) ) );
+ tester( bind( f, !bind( f, _1 ) ), true, f( !f( true ) ) );
 
     return boost::report_errors();
 }

Added: sandbox/SOC/2010/phoenix3/libs/phoenix/test/bug4853.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/bug4853.cpp 2011-01-22 13:23:32 EST (Sat, 22 Jan 2011)
@@ -0,0 +1,70 @@
+/*==============================================================================
+ Copyright (c) 2005-2010 Joel de Guzman
+ Copyright (c) 2010 Thomas Heller
+
+ 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 <boost/phoenix/core.hpp>
+#include <boost/phoenix/operator.hpp>
+#include <boost/phoenix/bind.hpp>
+#include <boost/range.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/range/adaptor/transformed.hpp>
+#include <boost/range/adaptor/uniqued.hpp>
+#include <boost/range/algorithm_ext/push_back.hpp>
+
+#include <vector>
+#include <string>
+
+
+namespace phoenix = boost::phoenix;
+
+struct Foo {
+ Foo(const std::string& name, int value)
+ : name_(name)
+ , value_(value)
+ { }
+
+ std::string name_; int value_;
+};
+
+typedef boost::shared_ptr<Foo> FooPtr;
+
+int range_test_complex() {
+ typedef std::vector<FooPtr> V;
+
+ V source;
+
+ source.push_back(boost::make_shared<Foo>("Foo", 10));
+ source.push_back(boost::make_shared<Foo>("Bar", 20));
+ source.push_back(boost::make_shared<Foo>("Baz", 30));
+ source.push_back(boost::make_shared<Foo>("Baz", 30)); //duplicate is here
+
+ std::vector<std::string> result1;
+ std::vector<int> result2;
+
+ using namespace boost::adaptors;
+ using phoenix::arg_names::arg1;
+
+ boost::push_back(result1, source | transformed(phoenix::bind(&Foo::name_, *arg1)) | uniqued);
+
+ for(unsigned i = 0; i < result1.size(); ++i)
+ std::cout << result1[i] << "\n";
+
+ boost::push_back(result2, source | transformed(phoenix::bind(&Foo::value_, *arg1)) | uniqued);
+
+ for(unsigned i = 0; i < result2.size(); ++i)
+ std::cout << result2[i] << "\n";
+
+ return 0;
+
+}
+
+int main()
+{
+ return range_test_complex();
+}
+


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