[proto] Problem using BOOST_PROTO_AUTO
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 <boost/proto/proto.hpp> #include <boost/proto/proto_typeof.hpp> #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<proto::terminal<var>, _var_tostr(proto::_value)> > {}; struct str_plus : std::plus<std::string>, proto::callable {}; struct foo_tostr : proto::or_ < proto::when<proto::function<proto::terminal<foo>, proto::vararg<proto::terminal<var> > >, proto::fold<proto::functional::pop_front(proto::_expr), string(), str_plus(proto::_state, var_tostr)> > > {}; 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
On 2/22/2010 6:12 PM, Manjunath Kudlur wrote:
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?
<snip> You're not doing anything wrong. You've uncovered a couple of const-correctness issues in proto and fusion. The big issue is that some fusion algorithms (e.g. fusion::pop_front, fusion::reverse) are not overloaded on const and non-const arguments. I've filed a bug against fusion and worked around the problem in proto. You can track the issue here: https://svn.boost.org/trac/boost/ticket/3954 -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (2)
-
Eric Niebler
-
Manjunath Kudlur