
"Robert Ramey" <ramey@rrsd.com> wrote in message news:ctojd3$obh$1@sea.gmane.org...
So lets make a minimalist dimensional analysis library whose function is to check arithmetic operations at compile time for consistency.
I will attempt to write a Concept definition keeping as close as possible to David Abrahams example. ie with an interface based in mpl Of course there are some subtleties that will raise eyebrows, but there aint much I can do except explain the rationale. For instance I would treat a *raw* set of dimensional-exponents as having no particular name, because one set can represent more than one quantity. (e.g torque and energy both have the same set of dimensional-exponents). the Units library must inform the dimensional analysis library regarding this to try to forestall backward compatibility issues. FWIW I'd put this in boost::pqs // eg typedef boost::pqs::abstract_quantity< boost::mpl::vector<x,y,z>, // set of dimensional exponents boost::pqs::energy_tag, // to distinguish from torque , also anonymous_tag for results of operations
energy;
// Not typedef boost::mpl::vector<x,y,z> energy ; (This is basically using the semantics and interface of pqs but implementing in boost style: http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/operations-semant... )
I'm not even convinced that fractional dimensions are needed.
It is possible they might occur in temporaries results of calculations in some cases. Its marginal but there are some eg opamp noise parameter that are specified as nanovolt per sqrt Hz.
If the really are, maybe the library can take a template paramter the specifies either an integer or compile time rational type.
AFAIK you may even be able to mix with boost::mpl::numeric_cast This would cleave off another tricky
piece - compile time rationals.
There are already several compile time rationals about (One I used is based on Matthias Schabels code).It should not be too hard to convert this to use the mpl style. This should enable Concept compatibility with whatever else might emerge as rational or fraction (e.g from Cromwell Enage). IOW A dimensional-exponent is a Concept essentially with an interface eg using mpl::plus etc. docs Might look like so: Concept DimensionalExponent // eg int_ , rational_c wish implements : mpl::plus<Dimensional ExponentL, Dimensional ExponentR> qa*qb mpl::minus<Dimensional ExponentL, Dimensional ExponentR> qa/qb mpl::multiplies<DimensionalExponent, Rational > pow<Rational>(q) mpl::equal<DimensionalExponentL,DimensionalExponentR> // dimensional analysis operator Concept DimensionalExponents // eg mpl::vector implements : mpl::plus<Dimensional ExponentsL, Dimensional ExponentsR> qa*qb mpl::minus<Dimensional ExponentsL, Dimensional ExponentsR> qa/qb mpl::multiplies<DimensionalExponents, Rational > pow<Rational>(q) mpl::equal<DimensionalExponentsL,DimensionalExponentsR> // dimensional analysis operator Concept AbstractQuantity // eg struct abstract_quantity implements : mpl::plus<AbstractQuantityL, AbstractQuantityR> qa*qb mpl::minus<AbstractQuantityL, AbstractQuantityR> qa/qb mpl::multiplies<AbstractQuantity, Rational > pow<Rational>(q) mpl::equal<AbstractQuantityL,AbstractQuantityR> // dimensional analysis operator negate, reciprocal also for convenience. regards Andy Little