Boost logo

Boost :

Subject: [boost] FW: Boost.Units problem with user-defined units and dimensionless quantities
From: Pieter (PieterB_at_[hidden])
Date: 2011-09-23 14:11:12


Thanks Steven. I now see the problem arises from using si::dimensionless
with nautical::length (The error message I get depends on the included
header files but is related to the operator+ (when absolute.hpp is included)
or the lack of a specialized add_typeof_helper in case that for example
si/area.hpp is included).

I guess my misconception was that I silently assumed that the
'dimensionless' type was acting as a normal double, reinforced by the fact
that the line with the pure multiplication (nm1 = d*nm2;) does compile OK.
The documentation says that " Because dimensionless quantities have no
associated units, they behave as normal scalars, and allow implicit
conversion to and from the underlying value type or types that are
convertible to/from that value type". I intended to use my TDimless type as
a 'generic' type for dimensionless quantities, but I now understand these
quantities still need to be related to a 'system' and every system would
need its own dimensionless type, even though there is no relation to the
base units that define the system.

Would I need to explicitly define conversions (e.g.
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(nautical::dimensionless,
si::dimensionless, double, 1.0); or is there a more elegant way to use
dimensionless quantities across systems?

Thanks again,

Pieter

-----Original Message-----
From: Steven Watanabe [mailto:watanabesj_at_[hidden]]
Sent: Friday, September 23, 2011 17:06
To: boost_at_[hidden]
Subject: Re: [boost] Boost.Units problem with user-defined units and
dimensionless quantities

AMDG

On 09/21/2011 12:29 PM, Pieter wrote:
> I am having some trouble using user-defined units and dimensionless once.
> Consider the example (taken straight from the documentation) that
> defines nautical miles (added at the bottom).
>
> When I do the following on VS2010:
>
> typedef quantity<boost::units::nautical::length> TDistanceInNMI;
> typedef quantity<dimensionless> TDimLess;
>
> TDistanceInNMI nm1,nm2,nm3;
> TDimLess d;
>
> nm1 = nm2 + nm3; // compiles OK
> nm1 = d*nm2; // compiles OK
> nm1 = nm2 + d*nm3; // does not compile, claims there is no operator+
> defined
>
> I suppose I might have to add a dimensionless type to the 'nautical'
> system, or have some misconceptions on how this should work. I tried
> adding the following line (mimicking some of the internal stuff) but
> that did not due to trick:
>
> typedef unit<dimensionless_type,system> dimensionless;
>

I'm surprised that this doesn't work. It seems to work when I try it. The
attached compiles with MSVC 2010.

> Could anyone tell me whether there is there anything I need to define
> to make this work?
>

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk