Boost logo

Boost Users :

Subject: Re: [Boost-users] [Units] Variant based runtime analysis
From: alfC (alfredo.correa_at_[hidden])
Date: 2011-02-28 13:34:19


On Feb 28, 2:06 am, Samuel Debionne <debio..._at_[hidden]> wrote:
> >> I have been playing with things like :
>
> >> quantity<variant<force, length, energy>  >
>
> > That won't work because variant<...>  is not a unit type. Can you post
> > a small example of what you want to achieve?
>
> Of course it won't work as is. But I did a bit of hacking in this direction.

the reason I asked for an example is because I was working in
something similar (not the same though).
>
> My aim is to be able to write something like this :
>
> any_quantity<force, length, energy> any_q = myfunction(...);
>
> ...
>
> quantity<force> = any_q; //runtime check
>

I think those quantities are so unrelated with each other from a
"type" point of view that you would be better of using templates.
Actually I do this a lot:

template<class Unit>
myfunction(quantity<Unit> q){
...
}

and also (if possible)

auto q = myfunction( ...);

> Is there any plan to have a runtime layer above Boost.Units (like boost
> GIL have dynamic any_images, any_view...) ?

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.

Good Luck,
Alfredo

>
> It would check the maximum at compile time (basically check if one the
> variant type could match the target quantity unit) and delegates the
> real check at runtime (throwing an exception if the conversion fails) ?
>
> IMHO it would be a lovely addition to the current library.
>
>  debionne.vcf
> < 1KViewDownload
>
> _______________________________________________
> Boost-users mailing list
> Boost-us..._at_[hidden]http://lists.boost.org/mailman/listinfo.cgi/boost-users


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