|
Boost Users : |
Subject: Re: [Boost-users] proto: analytical-only math functions
From: Eric Niebler (eric_at_[hidden])
Date: 2009-02-05 12:36:05
Hicham Mouline wrote:
> From: "Eric Niebler":
>> Hicham Mouline wrote:
>>> 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.
The attachments came through fine. What I don't understand is why you
would want these globals to be non-const, but really that's your
business. If it makes sense for your DSEL, then do it.
>>> 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?
No.
>>> 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.
I see. Yes, it can be sometimes be convenient for metafunction that
return MPL Integral Constants to have a nested ::value.
<snip>
> 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)?
I encourage you to try it yourself and mail back if you get stuck.
There's lots of good information on writing grammars in the docs, and
some complete examples that you can look at.
-- 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