Boost logo

Boost Users :

Subject: Re: [Boost-users] Units: adding quantities
From: Mark Volkmann (mark_at_[hidden])
Date: 2009-01-09 17:49:06


On Jan 9, 2009, at 4:41 PM, <peter_foelsche_at_[hidden]> wrote:

> I would not want to write any software that internally calculates
> with non-metric units.

Agreed. I wouldn't either. I'm just trying to learn how to use this
library now. The actual units aren't relevant to my questions. Suppose
I had a method that accepted meters and I had quantities of meters and
centimeters. How can I add two quantities that have different, but
related units? Obviously I could get the primitive values, multiple
centimeters by 100, add that to the number of meters and create a new
quantity. I just want to know if and how the Units library helps with
adding quantities of different units.

> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]
> ] On Behalf Of Mark Volkmann
> Sent: Friday, January 09, 2009 14:24
> To: Boost-users_at_[hidden]
> Subject: [Boost-users] Units: adding quantities
>
> I have a method that takes a parameter of type quantity<feet>
> where feet is defined by the following typedef:
>
> typedef boost::units::us::foot_base_unit::unit_type feet;
>
> I also have this typedef:
>
> typedef bu::us::inch_base_unit::unit_type inches;
>
> Do I really need to define a typedef like this for every measurement
> type I want to use? I certainly don't want to specify all those
> namespaces every time I use one of the measurement types, but this
> approach seems a bit tedious.
>
> I'd like to do something like this:
>
> a.setWingspan(195*feet() + 8*inches());
>
> but that doesn't work because there is no match for operator+.
>
> What's a good way to add inches to a feet quantity?
>
> ---
> Mark Volkmann
>
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

---
Mark Volkmann

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