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 and declared the terminals x and y with
proto::_ template arguments. Here is the complete program :
I re-worked the program as below to achieve what I need. But now,
using the DSEL with a new data-type becomes much more invasive,
because I need some rules to the grammar. May be there is a less
invasive and more elegant way? Also, I don't understand why I need
both This(tuple<>&) and This(const tuple<>&) versions in the
get_tuple_* classes. Removing either one of them causes a compiler
error.
#include <cassert>
#include
#include <iostream>
namespace proto = boost::proto;
template
struct tuple {
X x;
Y y;
};
struct arg_ {};
proto::terminal::type arg = {{}};
struct x_ {};
proto::terminal::type x = {{}};
struct y_ {};
proto::terminal::type y = {{}};
struct get_tuple_x
: proto::callable {
template<typename Sig>
struct result;
template
struct result &)> {
typedef X type;
};
template
struct result &)> {
typedef X type;
};
template
X operator()(tuple &t) const {
return t.x;
}
template
X operator()(const tuple &t) const {
return t.x;
}
};
struct get_tuple_y
: proto::callable {
template<typename Sig>
struct result;
template
struct result &)> {
typedef Y type;
};
template
struct result &)> {
typedef Y type;
};
template
Y operator()(tuple &t) const {
return t.y;
}
template
Y operator()(const tuple &t) const {
return t.y;
}
};
struct micro_lambda
: proto::or_<
proto::when<
proto::mem_ptr, proto::terminal >
, get_tuple_x(proto::_state)>
, proto::when<
proto::mem_ptr, proto::terminal >
, get_tuple_y(proto::_state)>
, proto::otherwise<
proto::_default
{} eval;
using namespace std;
int main()
{
tuple t;
t.x = 1;
t.y = 41.f;
cout << eval(arg->*x + arg->*y, t) << endl;
}
Manjunath