Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] Creating specific unit quantities
From: Matthias Schabel (boost_at_[hidden])
Date: 2011-03-03 12:02:33


> 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?

I don't really understand what you're trying to accomplish. You might want to have a look at the "Why can't I construct a quantity directly from the value type?" section in the FAQ. That explains why "si::length" and "meters" are different things...basically, "meters" is an instance of si::length.

Matthias


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