I have the following program to print out the arguments of a function
call expression. It works fine when I directly call the grammar on the
expression like so : foo_tostr()(f(a,b,c)). However, if I assign the
expression to a variable pr using BOOST_PROTO_AUTO and call
foo_tostr()(pr), I get error of the form "conversion from
‘boost::fusion::... to non-scalar type .... requested". Can someone
let me know what I am doing wrong?
#include <iostream>
#include
#include
#include <sstream>
#include <string>
using namespace std;
namespace proto = boost::proto;
unsigned ids;
struct var {
unsigned id;
var() {
id = ++ids;
}
};
struct foo {};
typedef proto::terminal<var>::type Var;
typedef proto::terminal<foo>::type Foo;
struct _var_tostr
: proto::callable {
typedef string result_type;
result_type operator()(var const &v) const {
stringstream sout;
sout << "v" << v.id << " ";
return sout.str();
}
result_type operator()(foo const &v) const {
stringstream sout;
sout << "foo(";
return sout.str();
}
};
struct var_tostr
: proto::or_<
proto::when
> {};
struct str_plus : std::plusstd::string, proto::callable {};
struct foo_tostr
: proto::or_ <
proto::when >,
proto::fold > > {};
int main()
{
Var a, b, c;
Foo f;
#define COPY_AND_PRINT
#ifdef COPY_AND_PRINT
BOOST_PROTO_AUTO(pr, (f(a,b,c)));
cout << foo_tostr()(pr) << endl;
#else
cout << foo_tostr()(f(a,b,c)) << endl;
#endif
}
--
Manjunath