Boost logo

Boost Users :

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


On Feb 28, 10:34 am, alfC <alfredo.cor..._at_[hidden]> wrote:
> 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){
> ...
>
> }
>

Also I forgot to mention that with the strategy above you have to
deduce the return type of the function, that depends on the logic of
function. typeof_helpers help in this case.

template<class Unit>
quantity< power_typeof_helper< multiply_typeof_helper < ...
Unit ... , ... >::type, ... >::type >
myfunction(quantity<Unit> q){
...

}

I know it can be a drag. I guess auto typed return types in C++0x can
help but I never tried.

Sorry for the splitted answer. In any case I would like to know of any
solution you can come up with.
Alfredo


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