Boost logo

Boost Users :

Subject: Re: [Boost-users] [Units] help with type-safe unit-specific conversions
From: Justin Leonard (justinleona_at_[hidden])
Date: 2009-07-23 14:51:12


> namespace wrap {
>
> template<Unit>
> void doSomethingWithLength(const quantity<Unit>& q)
> {
> return doSomethingWithLength((quantity<si::length>(q)).value());
> }
>
> } // namespace wrap
>
> Then you can call wrap::doSomethingWithLength with any unit having
> length dimension and the argument will be converted to meters and
> "demarshalled"...

If I understand the way quantity works correctly, this will take a quantity on
any length dimension and convert it to a quantity on si::length. What I am
attempting to do is manage quantities in units. What I mean by marshalling and
demarshalling is this:

quantity<si::length> marshall(double value) {
  return value * us::foot_base_unit();
}

double demarshall(const quantity<si::length>& value) {
  return quantity</*feet*/>(value).value();
}

If possible this is the approach I'd like to take,

Thanks
Justin
 


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