Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] Creating specific unit quantities
From: Ryan (mccorywork_at_[hidden])
Date: 2011-03-03 10:43:35


On Tue, Mar 1, 2011 at 10:19 PM, Ryan <mccorywork_at_[hidden]> wrote:
>
> Is it possible to create a quantity with a specific type of dimension
> value?
>
With some digging I've found that it's possible.

> using namespace boost::units;
> using namespace boost::units::si;
>
> quantity<length> L = 2.0*meters;
>
> //Is it possible to have meters instead of length as a quantity?
> quantity<???> L = 2.0 * meters;
>

quantity<meter_base_unit::unit_type> L = 2.0 * meters;

This quantity though doesn't naturally allow addition with quantity<length>.

quantity<length> L = 2.0 * meters;
quantity<meter_base_unit::unit_type> M = 3.0 * meters;

quantity<length> N = L + M;

This doesn't compile. The error is "Failed to specialize function template
'add_typeof_helpter'". If I explicit cast M to quantity<length> the code
compiles. The si::length is the meter. So why is this occuring?

Ryan



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