Boost logo

Boost :

Subject: [boost] [proto] Can't use functions in expressions?
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-09-01 11:36:46


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.


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