Boost logo

Boost Users :

Subject: Re: [Boost-users] [Units] Variant based runtime analysis
From: Samuel Debionne (debionne_at_[hidden])
Date: 2011-03-01 09:55:47


Alfredo,

Thank you for your answers. To be more pragmatic here is an archetype of
function that I have in my problem :

any_quantity<force, length> myfunction(energy_q arg1)
{
    if (arg1 > 1.0 * jouls)
       return 2.2 * newtons;
    else
       return 3.3 * meters;
}

That may sound weird but it's a real case. I'm solving a problem with
two quantities that have unrelated units and one quantiy or the other is
choosen at runtime depending on some state variable values.
Ultimately those quantities are stored in a single matrix. For now I
break the dimensionnal analysis at this step using plain doubles.

> I think this goes against the library design which is to be zero
> overhead. (But it may be useful some times although my pattern above
> is a good competition against your requested feature)

> What I was working on is something like:
>
> any_quantity<force_dimension>
>
> that can hold any quantity with force dimension, this makes more sense
> to me because at least I know the all force quantities are potentially
> convertible to one another, regardless of the unit system. In my
> proposal there is no runtime checking at all, but only runtime
> conversions.

Runtime conversion are also something I am interrested. Are you
following the lead of :

http://www.boost.org/doc/libs/1_46_0/doc/html/boost_units/Examples.html#boost_units.Examples.RuntimeUnits

I think that we could layer things this way :

LAYER 3: any_quantity<heterogeneous_units>
runtime dimensional analysis and conversion

LAYER 2: any_quantity<homogeneous_dimension_units>
compile time dimensional analysis and runtime conversion

LAYER 1: quantity<unit>
the actual library

Each extension layers could be build on top of the others.

For performance reason, the runtime dimensional analysis could be
switched off for release build.

> In any case I would like to know of any solution you can come up with.

Of course.


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