Boost logo

Boost Users :

Subject: Re: [Boost-users] proto: analytical-only math functions
From: Eric Niebler (eric_at_[hidden])
Date: 2009-03-14 13:37:03


Hicham Mouline wrote:
> Eric Niebler wrote:
>> And if I'm right in assuming that the first parameter of
>> derivative is which derivative to take, you'll need to make that
>> information available at compile-time as well, so:
>> let( f(x) = log(x) )[ g(x) = derivative<1>(f, x) ];
>
> I am thinking about user friendliness.
> I think I will have the user define this:
>
> typedef proto::terminal< function_tag< mpl::size_t<3> > >::type
> function3;
> function3 f( x1, x2, x3, x1+ x2+ x3+ c6 ); // after all, store the
> expression tree at runtime
>
> 1. Can I define a constructor for the terminal like this?

You could, but ...

> 2. Can I store the expression tree somewhere? Inside the function_tag
> template?

You could store the expression tree within such a function3 object, but
only by erasing its type. (See
http://www.artima.com/cppsource/type_erasure.html for more on type erasure.)

Look at the type "function3" you've defined above. It has absolutely no
compile-time information whatsoever about what expression might be
stored inside it. If you want to use this variable in more complicated
expressions and do expression template magic to compute derivatives and
stuff at compile time, you can't.

The options I offered above make all the compile-time information *about
the full expression* available to Proto so you can compute interesting
things at compile time.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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