Boost logo

Boost :

Subject: Re: [boost] [proto] Can't use functions in expressions?
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2011-09-01 12:21:25


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk