|
Boost Users : |
Subject: Re: [Boost-users] proto: analytical-only math functions
From: Eric Niebler (eric_at_[hidden])
Date: 2009-02-05 11:40:05
Hicham Mouline wrote:
> Hi Eric,
>
> Thank you for the LHS grammar. I have made the changes you suggested in the
> attached files.
>
> The main header <math.h> (I'll change this name later) includes constants
> (c0 ... c100), variables(x0... x100 and x y z S r q v t), basic functions
> from <cmath> and general functions defined by the user, with dimensions 0 to
> 100.
>
> Question1: With PP, I define constants c0 to c100, as non-const because I
> let the user initialize them to a integer variables or literals or floating
> point variables or literals.
I don't understand, but it probably doesn't matter.
> Does the non-constness matter? They are defined in a header file included by
> users of the library.
You'll have linker trouble if two translation units include that header.
You should define them in a .cpp file and mark them as extern in the header.
> Question2: With PP, I also define variables. I had variable_tag as a
> template taking <unsigned int subscript>.
> Not subscript has nothing to do with the dimensionality here. These are just
> different 1d variables.
> But then to match the proto:_ in the grammar, I high jacked your idea of a
> numerical MPL metafunction mpl::size_t<> for variables
> as well.
> Also, note the non-constness??
> What do you think of the stand alone x y z S .... non subscripted variables?
I'm not sure what you're asking here.
> Queestion3: I made dimension_of a numerical metafunction with an embedded
> value member.
OK, that's reasonable.
> What is the convenience
> of making metafunctions numerical?
I don't know what you're asking.
> Should dimension_of be specialized for
> function_tag<> templates rather than on any type,
> as:
> template <size_t dim>
> struct dimension_of< function_tag< mpl::size_t<dim> > >
> { ... };
>
> Any advantage to this?
No real advantage, but a couple of disadvantages. You'll find that with
this formulation, dimension_of< const function_tag<mpl::size_t<1> > > is
undefined (note the const).
> Question4: What is a quick way to test fundef_lhs_grammar does what I
> intend?
When I want to test a grammar, I define two functions like this:
template<typename E>
void assert_matches( E const & )
{
BOOST_MPL_ASSERT((proto::matches<E, fundef_lhs_grammar>));
}
template<typename E>
void assert_not_matches( E const & )
{
BOOST_MPL_ASSERT_NOT((proto::matches<E, fundef_lhs_grammar>));
}
Then in main(), I can create expressions and pass them to one of these
functions. Either it matches or it doesn't, and I can find out at
compile time.
HTH,
-- 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