Update of /cvsroot/boost/boost/libs/xpressive/proto/test
In directory 
sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13310/libs/xpressive/proto/test

Modified Files:
        lambda.cpp proto_fusion.cpp proto_fusion_s.cpp 
Log Message:
more work on BOOST_PROTO_EXTENDS

Index: lambda.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/proto/test/lambda.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- lambda.cpp  3 Feb 2007 00:14:33 -0000       1.6
+++ lambda.cpp  15 Feb 2007 23:06:56 -0000      1.7
@@ -23,7 +23,7 @@
 
 using namespace boost;
 
-struct lambda_domain {};
+struct lambda_domain : proto::domain<> {};
 template<typename I> struct placeholder { typedef I arity; };
 
 // Some custom transforms for calculating the max arity of a lambda expression
@@ -108,22 +108,11 @@
 // function objects
 template<typename T>
 struct lambda
-  : proto::extends<T, lambda<T>, lambda_domain>
 {
-    typedef proto::extends<T, lambda<T>, lambda_domain> base_type;
+    BOOST_PROTO_EXTENDS(T, lambda<T>, lambda_domain)
+    BOOST_PROTO_EXTENDS_ASSIGN(T, lambda<T>, lambda_domain)
+    BOOST_PROTO_EXTENDS_SUBSCRIPT(T, lambda<T>, lambda_domain)
     
-    lambda()
-      : base_type()
-    {}
-
-    lambda(T const &t)
-      : base_type(t)
-    {}
-
-    // This is needed because by default, the compiler-generated
-    // assignment operator hides the operator= defined in our base class.
-    using base_type::operator =;
-
     // Careful not to evaluate the return type of the nullary function
     // unless we have a nullary lambda!
     typedef typename mpl::eval_if<
@@ -164,32 +153,34 @@
 {
     // This causes expressions in the lambda domain to
     // be wrapped in a lambda<> expression wrapper.
-    template<typename Expr, typename Tag>
-    struct generate<lambda_domain, Expr, Tag>
+    template<typename Expr>
+    struct generate<lambda_domain, Expr>
     {
         typedef lambda<Expr> type;
 
         static type make(Expr const &expr)
         {
-            return lambda<Expr>(expr);
+            return type::make(expr);
         }
     };
 }}
 
 // Define some lambda placeholders
-lambda<proto::terminal<placeholder<mpl::int_<0> > >::type> const _1;
-lambda<proto::terminal<placeholder<mpl::int_<1> > >::type> const _2;
+lambda<proto::terminal<placeholder<mpl::int_<0> > >::type> const _1 = {{}};
+lambda<proto::terminal<placeholder<mpl::int_<1> > >::type> const _2 = {{}};
 
 template<typename T>
 lambda<typename proto::terminal<T>::type> const val(T const &t)
 {
-    return proto::terminal<T>::type::make(t);
+    lambda<typename proto::terminal<T>::type> that = {{t}};
+    return that;
 }
 
 template<typename T>
 lambda<typename proto::terminal<T &>::type> const var(T &t)
 {
-    return proto::terminal<T &>::type::make(t);
+    lambda<typename proto::terminal<T &>::type> that = {{t}};
+    return that;
 }
 
 void test_lambda()

Index: proto_fusion.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/proto/test/proto_fusion.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- proto_fusion.cpp    3 Feb 2007 00:14:33 -0000       1.2
+++ proto_fusion.cpp    15 Feb 2007 23:06:56 -0000      1.3
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// proto_fusion.hpp
+// proto_fusion.cpp
 //
 //  Copyright 2006 Eric Niebler. Distributed under the Boost
 //  Software License, Version 1.0. (See accompanying file
@@ -9,6 +9,7 @@
 #include <boost/xpressive/proto/fusion.hpp>
 #include <boost/fusion/algorithm/iteration/for_each.hpp>
 #include <boost/test/unit_test.hpp>
+#include <boost/utility/addressof.hpp>
 #include <sstream>
 
 boost::proto::terminal<char>::type a_ = {'a'};
@@ -21,11 +22,6 @@
 boost::proto::terminal<char>::type h_ = {'h'};
 boost::proto::terminal<char>::type i_ = {'i'};
 
-std::ostream &operator <<(std::ostream &sout, boost::proto::tag::terminal)
-{
-    return sout;
-}
-
 std::ostream &operator <<(std::ostream &sout, boost::proto::tag::right_shift)
 {
     return sout << ">>";
@@ -36,16 +32,22 @@
     return sout << "|";
 }
 
+template<typename Args>
+std::ostream &operator <<(std::ostream &sout, 
boost::proto::expr<boost::proto::tag::terminal, Args, 1> const *op)
+{
+    return sout << boost::proto::arg(*op);
+}
+
 template<typename Tag, typename Args>
-std::ostream &operator <<(std::ostream &sout, boost::proto::expr<Tag, Args, 1> 
const &op)
+std::ostream &operator <<(std::ostream &sout, boost::proto::expr<Tag, Args, 1> 
const *op)
 {
-    return sout << Tag() << boost::proto::arg(op);
+    return sout << Tag() << boost::addressof(boost::proto::arg(*op));
 }
 
 template<typename Tag, typename Args>
-std::ostream &operator <<(std::ostream &sout, boost::proto::expr<Tag, Args, 2> 
const &op)
+std::ostream &operator <<(std::ostream &sout, boost::proto::expr<Tag, Args, 2> 
const *op)
 {
-    return sout << boost::proto::left(op) << Tag() << boost::proto::right(op);
+    return sout << boost::addressof(boost::proto::left(*op)) << Tag() << 
boost::addressof(boost::proto::right(*op));
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -60,7 +62,7 @@
     template<typename Op>
     void operator()(Op const &op) const
     {
-        this->sout_ << '(' << op << ')';
+        this->sout_ << '(' << boost::addressof(op) << ')';
     }
 private:
     std::ostream &sout_;

Index: proto_fusion_s.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/proto/test/proto_fusion_s.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- proto_fusion_s.cpp  3 Feb 2007 00:14:33 -0000       1.2
+++ proto_fusion_s.cpp  15 Feb 2007 23:06:56 -0000      1.3
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// proto_fusion.hpp
+// proto_fusion_s.cpp
 //
 //  Copyright 2006 Eric Niebler. Distributed under the Boost
 //  Software License, Version 1.0. (See accompanying file
@@ -9,23 +9,9 @@
 #include <boost/xpressive/proto/fusion.hpp>
 #include <boost/fusion/algorithm/iteration/ext_/for_each_s.hpp>
 #include <boost/test/unit_test.hpp>
+#include <boost/utility/addressof.hpp>
 #include <sstream>
 
-boost::proto::terminal<char>::type a_ = {'a'};
-boost::proto::terminal<char>::type b_ = {'b'};
-boost::proto::terminal<char>::type c_ = {'c'};
-boost::proto::terminal<char>::type d_ = {'d'};
-boost::proto::terminal<char>::type e_ = {'e'};
-boost::proto::terminal<char>::type f_ = {'f'};
-boost::proto::terminal<char>::type g_ = {'g'};
-boost::proto::terminal<char>::type h_ = {'h'};
-boost::proto::terminal<char>::type i_ = {'i'};
-
-std::ostream &operator <<(std::ostream &sout, boost::proto::tag::terminal)
-{
-    return sout;
-}
-
 std::ostream &operator <<(std::ostream &sout, boost::proto::tag::right_shift)
 {
     return sout << ">>";
@@ -36,16 +22,22 @@
     return sout << "|";
 }
 
+template<typename Args>
+std::ostream &operator <<(std::ostream &sout, 
boost::proto::expr<boost::proto::tag::terminal, Args, 1> const *op)
+{
+    return sout << boost::proto::arg(*op);
+}
+
 template<typename Tag, typename Args>
-std::ostream &operator <<(std::ostream &sout, boost::proto::expr<Tag, Args, 1> 
const &op)
+std::ostream &operator <<(std::ostream &sout, boost::proto::expr<Tag, Args, 1> 
const *op)
 {
-    return sout << Tag() << boost::proto::arg(op);
+    return sout << Tag() << boost::addressof(boost::proto::arg(*op).cast());
 }
 
 template<typename Tag, typename Args>
-std::ostream &operator <<(std::ostream &sout, boost::proto::expr<Tag, Args, 2> 
const &op)
+std::ostream &operator <<(std::ostream &sout, boost::proto::expr<Tag, Args, 2> 
const *op)
 {
-    return sout << boost::proto::left(op) << Tag() << boost::proto::right(op);
+    return sout << boost::addressof(boost::proto::left(*op).cast()) << Tag() 
<< boost::addressof(boost::proto::right(*op).cast());
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -60,7 +52,7 @@
     template<typename Op>
     void operator()(Op const &op) const
     {
-        this->sout_ << '(' << op << ')';
+        this->sout_ << '(' << boost::addressof(op.cast()) << ')';
     }
 private:
     std::ostream &sout_;
@@ -68,6 +60,95 @@
 
 void test1()
 {
+    boost::proto::terminal<char>::type a_ = {'a'};
+    boost::proto::terminal<char>::type b_ = {'b'};
+    boost::proto::terminal<char>::type c_ = {'c'};
+    boost::proto::terminal<char>::type d_ = {'d'};
+    boost::proto::terminal<char>::type e_ = {'e'};
+    boost::proto::terminal<char>::type f_ = {'f'};
+    boost::proto::terminal<char>::type g_ = {'g'};
+    boost::proto::terminal<char>::type h_ = {'h'};
+    boost::proto::terminal<char>::type i_ = {'i'};
+
+    std::stringstream sout;
+
+    // Test for 1-way branching "tree"
+    sout.str("");
+    boost::fusion::for_each_s(!!!!(a_ >> b_), to_string(sout));
+    BOOST_CHECK_EQUAL("(a>>b)", sout.str());
+
+    // Tests for 2-way branching trees
+    sout.str("");
+    boost::fusion::for_each_s(a_ >> b_ >> c_, to_string(sout));
+    BOOST_CHECK_EQUAL("(a)(b)(c)", sout.str());
+
+    sout.str("");
+    boost::fusion::for_each_s(a_ | b_ | c_, to_string(sout));
+    BOOST_CHECK_EQUAL("(a)(b)(c)", sout.str());
+
+    sout.str("");
+    boost::fusion::for_each_s(a_ >> b_ | c_ >> d_, to_string(sout));
+    BOOST_CHECK_EQUAL("(a>>b)(c>>d)", sout.str());
+
+    sout.str("");
+    boost::fusion::for_each_s(a_ | b_ >> c_ | d_, to_string(sout));
+    BOOST_CHECK_EQUAL("(a)(b>>c)(d)", sout.str());
+
+    sout.str("");
+    boost::fusion::for_each_s(a_ >> b_ | c_ >> d_ | e_ >> f_ >> g_, 
to_string(sout));
+    BOOST_CHECK_EQUAL("(a>>b)(c>>d)(e>>f>>g)", sout.str());
+
+    sout.str("");
+    boost::fusion::for_each_s(a_ >> b_ | c_ >> d_ | e_ >> (f_ | g_) >> h_, 
to_string(sout));
+    BOOST_CHECK_EQUAL("(a>>b)(c>>d)(e>>f|g>>h)", sout.str());
+
+    // Test for n-way branching tree
+    sout.str("");
+    boost::fusion::for_each_s(a_(b_(c_ >> d_, e_ | f_), g_ >> h_)(i_), 
to_string(sout));
+    BOOST_CHECK_EQUAL("(a)(b)(c>>d)(e|f)(g>>h)(i)", sout.str());
+}
+
+////////////////////////////////////////////////////////////////////////
+// Test that EXTENDS expression wrappers are also valid fusion sequences
+
+struct MyDomain
+  : boost::proto::domain<>
+{};
+
+template<typename Expr>
+struct My
+{
+    BOOST_PROTO_EXTENDS(Expr, My<Expr>, MyDomain)
+    BOOST_PROTO_EXTENDS_ASSIGN(Expr, My<Expr>, MyDomain)
+    BOOST_PROTO_EXTENDS_SUBSCRIPT(Expr, My<Expr>, MyDomain)
+    BOOST_PROTO_EXTENDS_FUNCTION(Expr, My<Expr>, MyDomain)
+};
+
+namespace boost { namespace proto
+{
+    template<typename Expr>
+    struct generate< MyDomain, Expr >
+    {
+        typedef My<Expr> type;
+        static type make(Expr const &expr)
+        {
+            return type::make(expr);
+        }
+    };
+}}
+
+void test2()
+{
+    My<boost::proto::terminal<char>::type> a_ = {{'a'}};
+    My<boost::proto::terminal<char>::type> b_ = {{'b'}};
+    My<boost::proto::terminal<char>::type> c_ = {{'c'}};
+    My<boost::proto::terminal<char>::type> d_ = {{'d'}};
+    My<boost::proto::terminal<char>::type> e_ = {{'e'}};
+    My<boost::proto::terminal<char>::type> f_ = {{'f'}};
+    My<boost::proto::terminal<char>::type> g_ = {{'g'}};
+    My<boost::proto::terminal<char>::type> h_ = {{'h'}};
+    My<boost::proto::terminal<char>::type> i_ = {{'i'}};
+
     std::stringstream sout;
 
     // Test for 1-way branching "tree"
@@ -115,6 +196,7 @@
     test_suite *test = BOOST_TEST_SUITE("test proto and segmented fusion 
integration");
 
     test->add(BOOST_TEST_CASE(&test1));
+    test->add(BOOST_TEST_CASE(&test2));
 
     return test;
 }


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to