----- Original Message ----- From: "Eric Niebler"
To: boost-users@lists.boost.org Subject: Re: [Boost-users] proto: analytical-only math functions Date: Thu, 05 Feb 2009 08:40:05 -0800 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
(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. PP is boost.preprocessor. I forgot attached files don't appear in the mailing list. template <unsigned int subscript> struct constant_tag {};
proto::terminal< constant_tag<0> >::type c0 = {{}}; // with preprocessor, i define c0 ... c100 I don't want lib users, in a first use, to have to define constant names nor variable names themselves.
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. Right. Could i define them const and still assign values (like arithmetic literals) to them later on?
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.
I'm just asking about a general advice re whether to make metafunctions numerical whenever possible.
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
)); } template<typename E> void assert_not_matches( E const & ) { BOOST_MPL_ASSERT_NOT((proto::matches
)); } 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.
Great, will do. I'll leave the grammar of the RHS of = operator till later. My next question is about my constants. I want to allow this example of syntax: c35 = any expression of integral or floating point literals, of c++ runtime variables of integral or fp type (no bool no enums) of _other_ constants Later, a constant will be either undefined, or defined. if undefined, evaluations of expressions with that constant will keep that constant in, otherwise, the constant will be replaced by its value How do I write the grammar that allows any expression, but just with those 4 possibilies (c35)? regards,