[proto] Can't use functions in expressions?

So.... I have a function that returns an expression template of proto::tag::function type, like so: template <class Exp>\ typename proto::result_of::make_expr<\ proto::tag::function\ , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<Exp>::type>\ , detail::big_number_exp<Exp>\
::type const \ func(const detail::big_number_exp<Exp>& arg)\ {\ return proto::make_expr<proto::tag::function>(\ detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<Exp>::type>() \ , arg \ );\ }\
and it all works fine, until I try and use the result of such a function call in an expression: sqrt(arg) + arg yeilds: 1>m:\data\boost\sandbox\big_number\libs\math\ide\extended_real\scrap\scrap.cpp(25): error C2893: Failed to specialize function template 'const boost::proto::detail::enable_binary<boost::proto::domainns_::deduce_domain,boost::proto::detail::not_a_grammar,boost::mpl::or_<boost::proto::is_extension<T>,boost::proto::is_extension<Right>>,boost::proto::tag::plus,const Left,const Right>::type boost::proto::exprns_::operator +(const Left &,const Right &)' 1> With the following template arguments: 1> 'boost::math::detail::big_number_exp<Expr>' 1> with 1> [ 1> Expr=boost::proto::exprns_::basic_expr<boost::proto::tag::function,boost::proto::argsns_::list2<boost::math::detail::big_number_exp<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,boost::proto::argsns_::term<boost::math::detail::sqrt_funct<boost::math::mpfr_real_backend<50>>>,0>>,boost::math::detail::big_number_exp<boost::proto::exprns_::expr<boost::proto::tag::terminal,boost::proto::argsns_::term<boost::math::big_number<boost::math::mpfr_real_backend<50>> *>,0>>>,2> 1> ] 1> 'boost::math::mpfr_real_50' So I figured I needed to update my grammar, so I tried adding this case: template<> struct big_number_grammar_cases::case_<proto::tag::function> : proto::function< proto::_ > {}; But still no joy (same error message). Any ideas on what I'm doing wrong? BTW I couldn't find any examples of using proto::function in a grammar, it wasn't obvious to me what it's template arguments should be, or indeed whether this actually enabled the function call operator rather than my use case? Thanks, John.

On Thursday, September 01, 2011 04:36:46 PM John Maddock wrote:
So.... I have a function that returns an expression template of proto::tag::function type, like so:
template <class Exp>\ typename proto::result_of::make_expr<\ proto::tag::function\ , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<Exp>::type>\ , detail::big_number_exp<Exp>\
::type const \
func(const detail::big_number_exp<Exp>& arg)\ {\ return proto::make_expr<proto::tag::function>(\ detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<Exp>::type>() \ , arg \ );\ }\
and it all works fine, until I try and use the result of such a function call in an expression:
sqrt(arg) + arg
yeilds:
<snip>
So I figured I needed to update my grammar, so I tried adding this case:
template<> struct big_number_grammar_cases::case_<proto::tag::function>
: proto::function< proto::_ >
{};
But still no joy (same error message).
Any ideas on what I'm doing wrong?
you only validated nullary functions. compare to the call to make_expr: proto::make_expr<proto::tag::function>( detail::sqrt_funct<typename detail::backend_type<Exp>::type>() , arg ) and the proto grammar: proto::function< proto::_ > Which means, you want to match a unary proto expression with a binary proto expression.
BTW I couldn't find any examples of using proto::function in a grammar, it wasn't obvious to me what it's template arguments should be, or indeed whether this actually enabled the function call operator rather than my use case?
Just keep in mind, that proto::function is a expression that can have variadic children. The first is the function expression, and the remaining the function arguments. proto::vararg might help here.
Thanks, John.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

BTW I couldn't find any examples of using proto::function in a grammar, it wasn't obvious to me what it's template arguments should be, or indeed whether this actually enabled the function call operator rather than my use case?
Just keep in mind, that proto::function is a expression that can have variadic children. The first is the function expression, and the remaining the function arguments. proto::vararg might help here.
Got it, this needs to be documented under http://www.boost.org/doc/libs/1_47_0/doc/html/boost/proto/function.html though, and an example wouldn't harm either ;-) John.

On Thursday, September 01, 2011 06:05:27 PM John Maddock wrote:
BTW I couldn't find any examples of using proto::function in a grammar, it wasn't obvious to me what it's template arguments should be, or indeed whether this actually enabled the function call operator rather than my use case?
Just keep in mind, that proto::function is a expression that can have variadic children. The first is the function expression, and the remaining the function arguments. proto::vararg might help here.
Got it, this needs to be documented under http://www.boost.org/doc/libs/1_47_0/doc/html/boost/proto/function.html though, and an example wouldn't harm either ;-)
Have a look here: http://www.boost.org/doc/libs/1_47_0/doc/html/proto/users_guide.html#boost_p...
John.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Have a look here: http://www.boost.org/doc/libs/1_47_0/doc/html/proto/users_guide.html#boost_p...
I have: it's the guide I used for producing functions-returning-expressions in the first place. It says absolutely nothing about how functions are specified in grammars. John.

Le 01/09/2011 19:38, John Maddock a écrit :
Have a look here: http://www.boost.org/doc/libs/1_47_0/doc/html/proto/users_guide.html#boost_p...
I have: it's the guide I used for producing functions-returning-expressions in the first place. It says absolutely nothing about how functions are specified in grammars.
John. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
I usually prefer using make_expr than function and use nary_expr to match them in gramamrs

On 9/1/2011 1:05 PM, John Maddock wrote:
BTW I couldn't find any examples of using proto::function in a grammar, it wasn't obvious to me what it's template arguments should be, or indeed whether this actually enabled the function call operator rather than my use case?
Just keep in mind, that proto::function is a expression that can have variadic children. The first is the function expression, and the remaining the function arguments. proto::vararg might help here.
Got it, this needs to be documented under http://www.boost.org/doc/libs/1_47_0/doc/html/boost/proto/function.html though, and an example wouldn't harm either ;-)
You're right. I can't get to this now, but if you file a ticket, I'll get to it eventually. -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (4)
-
Eric Niebler
-
Joel Falcou
-
John Maddock
-
Thomas Heller