Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto?][Phoenix?] : Advice on creating lazy data structures
From: Manjunath Kudlur (keveman_at_[hidden])
Date: 2010-03-30 15:19:35


> <snip>
>
> Not necessarily. These these can be added to your DSEL post-hoc, and there
> are some fun games you can play with proto's operator->*. Consider the
> following program:

Thanks, Eric. That was an Ah-ha moment for me. I tried a different
variation of your program. I changed point to a templated
tuple<typename X, typename Y> and declared the terminals x and y with
proto::_ template arguments. Here is the complete program :

#include <cassert>
#include <boost/proto/proto.hpp>
#include <iostream>
namespace proto = boost::proto;

template<typename X, typename Y>
struct tuple {
  X x;
  Y y;
};

template<typename X, typename Y>
struct tuple_types {
  typedef X tuple<X, Y>::* X_type;
  typedef Y tuple<X, Y>::* Y_type;
};

//Does not work
// proto::terminal<tuple_types<proto::_, proto::_>::X_type>::type x
// = {&tuple<proto::_, proto::_>::x};
// proto::terminal<tuple_types<proto::_, proto::_>::Y_type>::type y
// = {&tuple<proto::_, proto::_>::y};

proto::terminal<tuple_types<int, float>::X_type>::type x
      = {&tuple<int, float>::x};
proto::terminal<tuple_types<int, float>::Y_type>::type y
      = {&tuple<int, float>::y};

struct arg_ {};
proto::terminal<arg_>::type arg = {{}};

struct micro_lambda
  : proto::or_<
proto::when<
proto::terminal<arg_>
, proto::_state
>
, proto::otherwise<
  proto::_default<micro_lambda>
>
>
{} eval;

using namespace std;

int main()
{
  tuple<int, float> t;
  t.x = 1;
  t.y = 41.f;

  cout << eval(arg->*x + arg->*y, t) << endl;
}

When I declare x and y like shown in the commented out part, I get
compile errors. What am I doing wrong there? Do I need extra grammar
rules to match the member pointers of a templated class?

Manjunath


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net