Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-11-12 16:43:08


Author: eric_niebler
Date: 2007-11-12 16:43:07 EST (Mon, 12 Nov 2007)
New Revision: 41044
URL: http://svn.boost.org/trac/boost/changeset/41044

Log:
examples improvements
Text files modified:
   branches/proto/v3/libs/xpressive/proto3/test/examples.cpp | 34 +++-
   branches/proto/v3/libs/xpressive/proto3/test/main.cpp | 236 +++++++++++++++++++--------------------
   2 files changed, 140 insertions(+), 130 deletions(-)

Modified: branches/proto/v3/libs/xpressive/proto3/test/examples.cpp
==============================================================================
--- branches/proto/v3/libs/xpressive/proto3/test/examples.cpp (original)
+++ branches/proto/v3/libs/xpressive/proto3/test/examples.cpp 2007-11-12 16:43:07 EST (Mon, 12 Nov 2007)
@@ -22,6 +22,7 @@
 using namespace transform;
 namespace mpl = boost::mpl;
 namespace fusion = boost::fusion;
+using boost::array;
 
 struct placeholder1 {};
 struct placeholder2 {};
@@ -176,6 +177,18 @@
     }
 };
 
+template<typename T>
+struct as_member
+{
+ typedef T type;
+};
+
+template<typename T, std::size_t N>
+struct as_member<T[N]>
+{
+ typedef array<T, N> type;
+};
+
 //[ AsArgList
 // This transform matches function invocations such as foo(1,'a',"b")
 // and transforms them into Fusion cons lists of their arguments. In this
@@ -189,7 +202,7 @@
       , reverse_fold<
             /*<< The first child expression of a `function<>` node is the
             function being invoked. We don't want that in our list, so use
- the `pop_front<>` transform to remove it. >>*/
+ the `pop_front()` to remove it. >>*/
             pop_front(_) // make (_) optional
           /*<< `nil` is the initial state used by the `reverse_fold<>`
           transform. >>*/
@@ -304,16 +317,15 @@
 
     using boost::fusion::cons;
     using boost::fusion::nil;
- // TODO
- //cons<int, cons<char, cons<char const (&)[2]> > > args(ArgsAsList::call( _1(1, 'a', "b"), i, i ));
- //BOOST_CHECK_EQUAL(args.car, 1);
- //BOOST_CHECK_EQUAL(args.cdr.car, 'a');
- //BOOST_CHECK_EQUAL(args.cdr.cdr.car, std::string("b"));
-
- //cons<int, cons<char, cons<char const (&)[2]> > > lst(FoldTreeToList::call( (_1 = 1, 'a', "b"), i, i ));
- //BOOST_CHECK_EQUAL(lst.car, 1);
- //BOOST_CHECK_EQUAL(lst.cdr.car, 'a');
- //BOOST_CHECK_EQUAL(lst.cdr.cdr.car, std::string("b"));
+ cons<int, cons<char, cons<std::string> > > args(ArgsAsList::call( _1(1, 'a', std::string("b")), i, i ));
+ BOOST_CHECK_EQUAL(args.car, 1);
+ BOOST_CHECK_EQUAL(args.cdr.car, 'a');
+ BOOST_CHECK_EQUAL(args.cdr.cdr.car, std::string("b"));
+
+ cons<int, cons<char, cons<std::string> > > lst(FoldTreeToList::call( (_1 = 1, 'a', std::string("b")), i, i ));
+ BOOST_CHECK_EQUAL(lst.car, 1);
+ BOOST_CHECK_EQUAL(lst.cdr.car, 'a');
+ BOOST_CHECK_EQUAL(lst.cdr.cdr.car, std::string("b"));
 
     plus<
         terminal<double>::type

Modified: branches/proto/v3/libs/xpressive/proto3/test/main.cpp
==============================================================================
--- branches/proto/v3/libs/xpressive/proto3/test/main.cpp (original)
+++ branches/proto/v3/libs/xpressive/proto3/test/main.cpp 2007-11-12 16:43:07 EST (Mon, 12 Nov 2007)
@@ -232,126 +232,124 @@
     terminal<int>::type u = {42};
     terminal<int>::type const t = {42};
 
- arg(u) = 43;
+ int j=0;
 
- //int j=0;
-
- //expr<tag::function,
- // args<
- // expr<tag::terminal, term<int> > const &
- // , expr<tag::terminal, term<int const &> >
- // , expr<tag::terminal, term<int &> >
- // , expr<tag::terminal, term<int> > const &
- // >
- //> that = t(1,j,t);
-
- //function<
- // expr<tag::terminal, term<int> > const &
- // , expr<tag::terminal, term<int const &> >
- // , expr<tag::terminal, term<int &> >
- // , expr<tag::terminal, term<int> > const &
- //>::type other = t(1,j,t);
-
- //expr<tag::assign,
- // args<
- // expr<tag::terminal, term<int> > const &
- // , expr<tag::terminal, term<int const &> >
- // >
- //> that2 = (t = 1);
-
- //expr<tag::posit,
- // args<expr<tag::terminal, term<int> > const &>
- //> that3 = +t;
-
- //expr<tag::posit,
- // args<expr<tag::terminal, term<int> > &>
- //> that4 = +u;
-
- //expr<tag::plus,
- // args<
- // expr<tag::terminal, term<int> > &
- // , expr<tag::terminal, term<int &> >
- // >
- //> that5 = u + j;
-
- //std::printf("%d %d\n", arg_c<0>(arg_c<0>(that5)), arg_c<0>(arg_c<1>(that5)));
-
- //check<_>(u+j);
- //check<terminal<int> >(u);
- //check<plus<terminal<int>, terminal<int&> > >(u + j);
- //check<plus<terminal<int>, terminal<int> > >(u + j);
-
- //terminal<pair<int,double> >::type w = {};
- //check<terminal<pair<int,double> > >(w);
- //check<terminal<pair<_,double> > >(w);
-
- //check<
- // or_<
- // minus<terminal<int>, terminal<int> >
- // , plus<terminal<int>, terminal<int> >
- // >
- //>(u + j);
-
- //check<function<Any> >(char_());
- //check<function<Any, Char, Char> >(char_('a', 'b'));
-
- //check_not<function<Any, Char> >(char_());
- //check<function<Any, Char> >(char_('a'));
- //check_not<function<Any, Char> >(char_('a', 'b'));
-
- //check<function<Any, vararg<Char> > >(char_());
- //check<function<Any, vararg<Char> > >(char_('a'));
- //check<function<Any, vararg<Char> > >(char_('a', 'b'));
-
- //terminal<float>::type ff = {1.F};
- //check<Promote>(ff+ff);
- //plus<terminal<double>::type, terminal<double>::type>::type dd =
- // Promote::call(ff+ff, dummy, non_);
-
- //plus<terminal<double>::type, terminal<int>::type>::type du =
- // Promote::call(ff+u, dummy, non_);
- //std::printf("%g %d\n", arg_c<0>(arg_c<0>(du)), arg_c<0>(arg_c<1>(du)));
-
- //plus<negate<terminal<double>::type>::type, terminal<int>::type>::type ndu =
- // Promote::call(+ff+u, dummy, non_);
- //std::printf("%g %d\n", arg_c<0>(arg_c<0>(arg_c<0>(ndu))), arg_c<0>(arg_c<1>(ndu)));
-
- //terminal<char const *>::type sz = {"hello"};
- //std::string str = Promote::call(sz, dummy, non_);
-
- //std::printf(
- // "%d %d %d\n"
- // , (int)Arity::call(sz, dummy, non_)
- // , (int)Arity::call(_1 + 0, dummy, non_)
- // , (int)Arity::call(_2 + _1, dummy, non_)
- //);
-
- //using fusion::cons;
- //cons<char, cons<int, cons<float> > > mylist1 =
- // ArgsAsList::call(_1('a', 42, 3.14f), dummy, non_);
- //std::cout << mylist1.car << ' ' << mylist1.cdr.car << ' ' << mylist1.cdr.cdr.car << std::endl;
-
- //cons<int, cons<char, cons<std::string> > > mylist2
- // (FoldTreeToList::call( (_1 = 1, 'a', str), dummy, non_ ));
- //std::cout << mylist2.car << ' ' << mylist2.cdr.car << ' ' << mylist2.cdr.cdr.car << std::endl;
-
- //default_context ctx;
- //int r1 = eval(as_expr(1) + as_expr(2), ctx);
- //std::cout << r1 << std::endl;
-
- //display_expr((_1 = 1, 'a', str));
-
- //byvalexpr<
- // expr<tag::plus
- // , args<
- // byvalexpr<expr<tag::terminal, term<int> > >
- // , byvalexpr<expr<tag::divides, args<
- // byvalexpr<expr<tag::terminal, term<int> > >
- // , byvalexpr<expr<tag::terminal, term<int> > >
- // > > >
- // >
- // >
- //> bve = A+B/C;
+ expr<tag::function,
+ args<
+ expr<tag::terminal, term<int> > const &
+ , expr<tag::terminal, term<int const &> >
+ , expr<tag::terminal, term<int &> >
+ , expr<tag::terminal, term<int> > const &
+ >
+ > that = t(1,j,t);
+
+ function<
+ expr<tag::terminal, term<int> > const &
+ , expr<tag::terminal, term<int const &> >
+ , expr<tag::terminal, term<int &> >
+ , expr<tag::terminal, term<int> > const &
+ >::type other = t(1,j,t);
+
+ expr<tag::assign,
+ args<
+ expr<tag::terminal, term<int> > const &
+ , expr<tag::terminal, term<int const &> >
+ >
+ > that2 = (t = 1);
+
+ expr<tag::posit,
+ args<expr<tag::terminal, term<int> > const &>
+ > that3 = +t;
+
+ expr<tag::posit,
+ args<expr<tag::terminal, term<int> > &>
+ > that4 = +u;
+
+ expr<tag::plus,
+ args<
+ expr<tag::terminal, term<int> > &
+ , expr<tag::terminal, term<int &> >
+ >
+ > that5 = u + j;
+
+ std::printf("%d %d\n", arg_c<0>(arg_c<0>(that5)), arg_c<0>(arg_c<1>(that5)));
+
+ check<_>(u+j);
+ check<terminal<int> >(u);
+ check<plus<terminal<int>, terminal<int&> > >(u + j);
+ check<plus<terminal<int>, terminal<int> > >(u + j);
+
+ terminal<pair<int,double> >::type w = {};
+ check<terminal<pair<int,double> > >(w);
+ check<terminal<pair<_,double> > >(w);
+
+ check<
+ or_<
+ minus<terminal<int>, terminal<int> >
+ , plus<terminal<int>, terminal<int> >
+ >
+ >(u + j);
+
+ check<function<Any> >(char_());
+ check<function<Any, Char, Char> >(char_('a', 'b'));
+
+ check_not<function<Any, Char> >(char_());
+ check<function<Any, Char> >(char_('a'));
+ check_not<function<Any, Char> >(char_('a', 'b'));
+
+ check<function<Any, vararg<Char> > >(char_());
+ check<function<Any, vararg<Char> > >(char_('a'));
+ check<function<Any, vararg<Char> > >(char_('a', 'b'));
+
+ terminal<float>::type ff = {1.F};
+ check<Promote>(ff+ff);
+ plus<terminal<double>::type, terminal<double>::type>::type dd =
+ Promote::call(ff+ff, dummy, non_);
+
+ plus<terminal<double>::type, terminal<int>::type>::type du =
+ Promote::call(ff+u, dummy, non_);
+ std::printf("%g %d\n", arg_c<0>(arg_c<0>(du)), arg_c<0>(arg_c<1>(du)));
+
+ plus<negate<terminal<double>::type>::type, terminal<int>::type>::type ndu =
+ Promote::call(+ff+u, dummy, non_);
+ std::printf("%g %d\n", arg_c<0>(arg_c<0>(arg_c<0>(ndu))), arg_c<0>(arg_c<1>(ndu)));
+
+ terminal<char const *>::type sz = {"hello"};
+ std::string str = Promote::call(sz, dummy, non_);
+
+ std::printf(
+ "%d %d %d\n"
+ , (int)Arity::call(sz, dummy, non_)
+ , (int)Arity::call(_1 + 0, dummy, non_)
+ , (int)Arity::call(_2 + _1, dummy, non_)
+ );
+
+ using fusion::cons;
+ cons<char, cons<int, cons<float> > > mylist1 =
+ ArgsAsList::call(_1('a', 42, 3.14f), dummy, non_);
+ std::cout << mylist1.car << ' ' << mylist1.cdr.car << ' ' << mylist1.cdr.cdr.car << std::endl;
+
+ cons<int, cons<char, cons<std::string> > > mylist2
+ (FoldTreeToList::call( (_1 = 1, 'a', str), dummy, non_ ));
+ std::cout << mylist2.car << ' ' << mylist2.cdr.car << ' ' << mylist2.cdr.cdr.car << std::endl;
+
+ default_context ctx;
+ int r1 = eval(as_expr(1) + as_expr(2), ctx);
+ std::cout << r1 << std::endl;
+
+ display_expr((_1 = 1, 'a', str));
+
+ byvalexpr<
+ expr<tag::plus
+ , args<
+ byvalexpr<expr<tag::terminal, term<int> > >
+ , byvalexpr<expr<tag::divides, args<
+ byvalexpr<expr<tag::terminal, term<int> > >
+ , byvalexpr<expr<tag::terminal, term<int> > >
+ > > >
+ >
+ >
+ > bve = A+B/C;
 
     return 0;
 }


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