|
Boost Users : |
Subject: Re: [Boost-users] proto: analytical-only math functions
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-03-05 02:11:24
-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Eric Niebler
Sent: 01 March 2009 02:33
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] proto: analytical-only math functions
Hicham Mouline wrote:
>
> Hello,
> I pasted the code I have so far in
> http://codepad.org/gk9KoR31
> a really cool tool indeed.
>
<snip>
>
> My questions (please refer to the code):
>
<snip>
>Hi Hicham,
>First let me apologize for not answering your questions the first time
>you posted them. I thought, "That's a lot of questions. I'll get to it
>when I have time." And I just haven't. Some of your questions are easy,
>though, so I'll give you some tips and get to the rest as time allows.
Please. I and I'm sure others are grateful for proto.
>proto::_ can only match types, not non-type template parameters, so you
>need to change constant_tag to take an MPL Integral Constant.
>The first parameter to proto::extends must be an expression type, so on
>line 47, you should probably have "typename
>proto::terminal<constant_tag<subscript> >::type", or something.
>On line 56, make it: proto::terminal< proto::convertible_to<double> > to
>match any terminal expression that is convertible to a double. (It says
>so much in the users' guide in the section "fuzzy and exact matches of
>terminals".)
>You really need to reread the section on domains again. The parameter to
>proto::generator must be an expression extension class template.
>That's all I have for now. Good luck. And be sure to check the docs,
>because you could have found many of these answers there.
The complication comes in my case from the fact that the grammar is not
stand alone type but an inner-type.
I have a new question. I am trying to make my basic functions (the cmath
ones)
lazy functions as in the user guide.
// to represent the c++03 math functions
// c++0x math functions are commented out.
template < double (*basic_function_ptr)(double) >
struct basic_function_tag {
typedef double result_type;
result_type operator()(double d) const { return basic_function_ptr(d); }
};
proto::terminal< basic_function_tag<std::sin> >::type const sinfct = {{}};
// Define a lazy sin
//
template<typename Arg>
typename proto::result_of::make_expr<
proto::tag::function, // Tag type
basic_function_tag<std::sin>, // First child (by value)
Arg const & // Second child (by
reference)
>::type
sin(Arg const &arg)
{
return proto::make_expr<proto::tag::function>(
basic_function_tag< std::sin >(), // First child (by value)
boost::ref(arg) // Second child (by
reference)
);
}
This should work for sin( literals and c++ vars ) and for sin( proto
expressions ).
As in my grammar I used to accept basic functions as proto terminals ,
How can I change the grammar to take this new sin() instead?
Regards,
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net